Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -113,18 +113,23 @@ if prompt := st.chat_input("Ask me anything.."):
|
|
113 |
|
114 |
# Insert data into the table
|
115 |
try :
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
113 |
|
114 |
# Insert data into the table
|
115 |
try :
|
116 |
+
try :
|
117 |
+
cur = st.session_state.conn.cursor()
|
118 |
+
except:
|
119 |
+
get_db_connection.clear()
|
120 |
+
st.session_state.conn = get_db_connection(POSTGRE_URL)
|
121 |
+
cur = st.session_state.conn.cursor()
|
122 |
+
|
123 |
+
cur.execute(
|
124 |
+
f"INSERT INTO chat_history (input_text, response_text, created_at) VALUES (%s, %s, %s)",
|
125 |
+
(prompt, response, datetime.now(timezone.utc) + timedelta(hours=7))
|
126 |
+
)
|
127 |
|
128 |
+
# Commit the transaction
|
129 |
+
st.session_state.conn.commit()
|
130 |
+
cur.close()
|
131 |
+
except Exception as e:
|
132 |
+
print("ERROR!!!\n", str(e))
|
133 |
+
print("User Input :", prompt)
|
134 |
+
print("Chatbot Response :", response)
|
135 |
+
|
|