garyd1 commited on
Commit
a503c00
·
verified ·
1 Parent(s): efe4ee0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -18,14 +18,15 @@ st.set_page_config(page_title="Enhanced Gemini Q&A App", layout="wide")
18
  if "chat_history" not in st.session_state:
19
  st.session_state.chat_history = [] # Empty list for chat history
20
 
 
21
  # Function to get response from Gemini API
22
  def get_gemini_response(question):
23
  # Reformat the session chat history to match the API requirements
24
  formatted_history = [
25
- {"content": chat["user"], "role": "user"} if "user" in chat else {"content": chat["bot"], "role": "bot"}
26
  for chat in st.session_state.chat_history
27
  ]
28
- chat = model.start_chat(history=formatted_history) # Use the formatted history
29
  try:
30
  response = chat.send_message(question, stream=True)
31
  full_response = ""
@@ -36,6 +37,7 @@ def get_gemini_response(question):
36
  except Exception as e:
37
  return f"Error: {str(e)}"
38
 
 
39
  # UI Layout
40
  st.title("🤖 Gemini AI - Interactive Q&A")
41
  st.write("Ask me anything and I'll try to answer!")
 
18
  if "chat_history" not in st.session_state:
19
  st.session_state.chat_history = [] # Empty list for chat history
20
 
21
+ # Function to get response from Gemini API
22
  # Function to get response from Gemini API
23
  def get_gemini_response(question):
24
  # Reformat the session chat history to match the API requirements
25
  formatted_history = [
26
+ {"parts": [{"text": chat["user"]}], "role": "user"} if "user" in chat else {"parts": [{"text": chat["bot"]}], "role": "bot"}
27
  for chat in st.session_state.chat_history
28
  ]
29
+ chat = model.start_chat(history=formatted_history) # Use the correctly formatted history
30
  try:
31
  response = chat.send_message(question, stream=True)
32
  full_response = ""
 
37
  except Exception as e:
38
  return f"Error: {str(e)}"
39
 
40
+
41
  # UI Layout
42
  st.title("🤖 Gemini AI - Interactive Q&A")
43
  st.write("Ask me anything and I'll try to answer!")