ziyadsuper2017 commited on
Commit
96d0abe
·
1 Parent(s): aa89276

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -60,7 +60,7 @@ chat_history = st.session_state.get("chat_history", [])
60
 
61
  # Display previous messages
62
  for message in chat_history:
63
- role, text = message
64
  st.markdown(f"**{role.title()}:** {text}")
65
 
66
  # Get user input from text box
@@ -69,7 +69,7 @@ user_input = st.text_input("You")
69
  # Check if user input is not empty
70
  if user_input:
71
  # Add user message to chat history
72
- chat_history.append({"role": "user", "parts": [user_input]})
73
 
74
  # Display user message with markdown
75
  st.markdown(f"**You:** {user_input}")
@@ -79,10 +79,10 @@ if user_input:
79
  response = model.generate_content(chat_history)
80
 
81
  # Get response text from response object
82
- response_text = response.text
83
 
84
  # Add response message to chat history
85
- chat_history.append({"role": "assistant", "parts": [response_text]})
86
 
87
  # Display response message with markdown
88
  st.markdown(f"**Gemini Bot:** {response_text}")
@@ -108,7 +108,7 @@ if st.button("Clear History"):
108
 
109
  # Save chat history to database
110
  for message in chat_history:
111
- c.execute("INSERT INTO history VALUES (?, ?)", (message["role"], message["parts"][0]))
112
  conn.commit()
113
 
114
  # Close the connection
 
60
 
61
  # Display previous messages
62
  for message in chat_history:
63
+ role, text = message["role"], message["content"]
64
  st.markdown(f"**{role.title()}:** {text}")
65
 
66
  # Get user input from text box
 
69
  # Check if user input is not empty
70
  if user_input:
71
  # Add user message to chat history
72
+ chat_history.append({"role": "user", "content": user_input})
73
 
74
  # Display user message with markdown
75
  st.markdown(f"**You:** {user_input}")
 
79
  response = model.generate_content(chat_history)
80
 
81
  # Get response text from response object
82
+ response_text = response.result.text
83
 
84
  # Add response message to chat history
85
+ chat_history.append({"role": "assistant", "content": response_text})
86
 
87
  # Display response message with markdown
88
  st.markdown(f"**Gemini Bot:** {response_text}")
 
108
 
109
  # Save chat history to database
110
  for message in chat_history:
111
+ c.execute("INSERT INTO history VALUES (?, ?)", (message["role"], message["content"]))
112
  conn.commit()
113
 
114
  # Close the connection