ziyadsuper2017 commited on
Commit
685cc0f
·
1 Parent(s): 2c99da2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -22
app.py CHANGED
@@ -162,25 +162,24 @@ try:
162
  )
163
  except Exception as e:
164
  st.write(f"An error occurred: {e}")
165
- # No need to return here
166
-
167
- # Add model response to chat history
168
- st.session_state["chat_history"].append({"role": "model", "parts": [{"text": response}]})
169
-
170
- # Display chat history
171
- for message in st.session_state["chat_history"]:
172
- r, t = message["role"], message["parts"][0]["text"]
173
- st.markdown(f"**{r.title()}:** {t}")
174
-
175
- # Save chat history to database
176
- for message in st.session_state["chat_history"]:
177
- if len(st.session_state["chat_history"]) % 2 == 0:
178
- role = "user"
179
- else:
180
- role = "model"
181
- text = str(message["parts"][0]["text"]) # Ensure the text is a string
182
- c.execute("INSERT INTO history VALUES (?, ?)", (role, text))
183
- conn.commit()
184
-
185
- # Clear user input
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 = ""