jonathanjordan21 commited on
Commit
66b7b89
1 Parent(s): 8da4159

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
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
- cur = st.session_state.conn.cursor()
117
- except:
118
- get_db_connection.clear()
119
- st.session_state.conn = get_db_connection(POSTGRE_URL)
120
- cur = st.session_state.conn.cursor()
 
 
 
 
 
 
121
 
122
- cur.execute(
123
- f"INSERT INTO chat_history (input_text, response_text, created_at) VALUES (%s, %s, %s)",
124
- (prompt, response, datetime.now(timezone.utc) + timedelta(hours=7))
125
- )
126
-
127
- # Commit the transaction
128
- st.session_state.conn.commit()
129
- cur.close()
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
+