Spaces:
Runtime error
Runtime error
ziyadsuper2017
commited on
Commit
·
2d04232
1
Parent(s):
1d3466d
Update app.py
Browse files
app.py
CHANGED
@@ -38,20 +38,23 @@ user_input = st.text_input("You")
|
|
38 |
# Check if user input is not empty
|
39 |
if user_input:
|
40 |
# Add user message to chat history
|
41 |
-
chat_history.append(("
|
42 |
|
43 |
# Create model object
|
44 |
model = genai.GenerativeModel(model_name="gemini-pro")
|
45 |
|
|
|
|
|
|
|
46 |
# Get model response with generate_content method
|
47 |
with st.spinner("Thinking..."):
|
48 |
-
response = model.generate_content(
|
49 |
|
50 |
# Get response text from response object
|
51 |
response_text = response.text
|
52 |
|
53 |
# Add response message to chat history
|
54 |
-
chat_history.append(("
|
55 |
|
56 |
# Update session state with chat history
|
57 |
st.session_state["chat_history"] = chat_history
|
|
|
38 |
# Check if user input is not empty
|
39 |
if user_input:
|
40 |
# Add user message to chat history
|
41 |
+
chat_history.append(("user", user_input))
|
42 |
|
43 |
# Create model object
|
44 |
model = genai.GenerativeModel(model_name="gemini-pro")
|
45 |
|
46 |
+
# Prepare chat history for generate_content method
|
47 |
+
genai_chat_history = [{"role": role, "content": text} for role, text in chat_history]
|
48 |
+
|
49 |
# Get model response with generate_content method
|
50 |
with st.spinner("Thinking..."):
|
51 |
+
response = model.generate_content(genai_chat_history)
|
52 |
|
53 |
# Get response text from response object
|
54 |
response_text = response.text
|
55 |
|
56 |
# Add response message to chat history
|
57 |
+
chat_history.append(("assistant", response_text))
|
58 |
|
59 |
# Update session state with chat history
|
60 |
st.session_state["chat_history"] = chat_history
|