ziyadsuper2017 commited on
Commit
22dd94c
·
1 Parent(s): e5757a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -26
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
- chat_history.append({"role": role, "parts": [{"text": user_input}]})
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
- r, t = message["role"], message["parts"][0]["text"]
70
- st.markdown(f"**{r.title()}:** {t}")
 
 
71
 
72
- # Save and display chat history
 
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()