Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 13 |
-
|
| 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 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
conn.
|
| 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 |
+
|