Spaces:
Runtime error
Runtime error
Commit
·
22dd94c
1
Parent(s):
e5757a8
Update app.py
Browse files
app.py
CHANGED
@@ -38,35 +38,30 @@ else:
|
|
38 |
for message in chat_history:
|
39 |
r, t = message["role"], message["parts"][0]["text"]
|
40 |
st.markdown(f"**{r.title()}:** {t}")
|
41 |
-
|
42 |
user_input = st.text_input("")
|
43 |
-
|
44 |
if user_input:
|
45 |
-
|
46 |
-
|
47 |
-
if role == "user":
|
48 |
-
response = model.generate_content(chat_history)
|
49 |
-
response_text = response.text
|
50 |
-
|
51 |
-
chat_history.append({"role": "model", "parts": [{"text": response_text}]})
|
52 |
|
53 |
-
if st.button("Display History"):
|
54 |
-
c.execute("SELECT * FROM history")
|
55 |
-
rows = c.fetchall()
|
56 |
-
|
57 |
-
for row in rows:
|
58 |
-
st.markdown(f"**{row[0].title()}:** {row[1]}")
|
59 |
-
|
60 |
-
# Save chat history to database
|
61 |
-
for message in chat_history:
|
62 |
-
c.execute("INSERT INTO history VALUES (?, ?)",
|
63 |
-
(message["role"], message["parts"][0]["text"]))
|
64 |
-
conn.commit()
|
65 |
-
|
66 |
st.session_state["chat_history"] = chat_history
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
for message in chat_history:
|
69 |
-
|
70 |
-
|
|
|
|
|
71 |
|
72 |
-
|
|
|
38 |
for message in chat_history:
|
39 |
r, t = message["role"], message["parts"][0]["text"]
|
40 |
st.markdown(f"**{r.title()}:** {t}")
|
41 |
+
|
42 |
user_input = st.text_input("")
|
43 |
+
|
44 |
if user_input:
|
45 |
+
# Existing code
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
st.session_state["chat_history"] = chat_history
|
48 |
+
|
49 |
+
# Replace display code
|
50 |
+
displayed_msgs = []
|
51 |
+
for message in chat_history:
|
52 |
+
if message not in displayed_msgs:
|
53 |
+
r, t = message["role"], message["parts"][0]["text"]
|
54 |
+
st.markdown(f"**{r.title()}:** {t}")
|
55 |
+
displayed_msgs.append(message)
|
56 |
+
|
57 |
+
if st.button("Display History"):
|
58 |
+
# Non-duplicate display code
|
59 |
+
|
60 |
+
# Replace insert code
|
61 |
for message in chat_history:
|
62 |
+
if message not in rows:
|
63 |
+
c.execute("INSERT INTO history VALUES (?, ?)",
|
64 |
+
(message["role"], message["parts"][0]["text"]))
|
65 |
+
conn.commit()
|
66 |
|
67 |
+
conn.close()
|