Mpavan45 commited on
Commit
ab9d33f
·
verified ·
1 Parent(s): ec32198

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -9,20 +9,24 @@ from langchain_community.chat_message_histories import SQLChatMessageHistory
9
  from langchain_core.runnables.history import RunnableWithMessageHistory
10
 
11
  st.write('hello welecome to data science tutor')
12
- db=chat_history_data
13
- conn=st.connection('db',type='sql')
14
- cursor=conn.cursor()
15
- # Create a table to store the session history (if it doesn't already exist)
16
- cursor.execute('''CREATE TABLE IF NOT EXISTS message_history (
17
- session_id TEXT NOT NULL,
18
- user_message TEXT NOT NULL,
19
- assistant_message TEXT,
20
- timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
21
- PRIMARY KEY (session_id, timestamp))''')
22
 
23
- # Commit the changes
24
- conn.commit()
25
-
26
- # Close the connection
27
- conn.close()
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  from langchain_core.runnables.history import RunnableWithMessageHistory
10
 
11
  st.write('hello welecome to data science tutor')
12
+ # Database file name
13
+ DB_PATH = "database.db"
 
 
 
 
 
 
 
 
14
 
15
+ # Function to create a database and table if not exists
16
+ def create_database():
17
+ if not os.path.exists(DB_PATH): # Check if database exists
18
+ conn = sqlite3.connect(DB_PATH)
19
+ cursor = conn.cursor()
20
 
21
+ # Create a sample table
22
+ cursor.execute("""
23
+ CREATE TABLE IF NOT EXISTS users (
24
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
25
+ name TEXT NOT NULL,
26
+ age INTEGER NOT NULL
27
+ )
28
+ """)
29
+ conn.commit()
30
+ conn.close()
31
+ st.success("Database and table created successfully!")
32
+