Spaces:
Runtime error
Runtime error
Commit
·
685cc0f
1
Parent(s):
2c99da2
Update app.py
Browse files
app.py
CHANGED
@@ -162,25 +162,24 @@ try:
|
|
162 |
)
|
163 |
except Exception as e:
|
164 |
st.write(f"An error occurred: {e}")
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
st.session_state.user_input = ""
|
|
|
162 |
)
|
163 |
except Exception as e:
|
164 |
st.write(f"An error occurred: {e}")
|
165 |
+
|
166 |
+
# Add model response to chat history
|
167 |
+
st.session_state["chat_history"].append({"role": "model", "parts": [{"text": response}]})
|
168 |
+
|
169 |
+
# Display chat history
|
170 |
+
for message in st.session_state["chat_history"]:
|
171 |
+
r, t = message["role"], message["parts"][0]["text"]
|
172 |
+
st.markdown(f"**{r.title()}:** {t}")
|
173 |
+
|
174 |
+
# Save chat history to database
|
175 |
+
for message in st.session_state["chat_history"]:
|
176 |
+
if len(st.session_state["chat_history"]) % 2 == 0:
|
177 |
+
role = "user"
|
178 |
+
else:
|
179 |
+
role = "model"
|
180 |
+
text = str(message["parts"][0]["text"]) # Ensure the text is a string
|
181 |
+
c.execute("INSERT INTO history VALUES (?, ?)", (role, text))
|
182 |
+
conn.commit()
|
183 |
+
|
184 |
+
# Clear user input
|
185 |
+
st.session_state.user_input = ""
|
|