Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -122,18 +122,21 @@ if prompt := st.chat_input("Hey?"):
|
|
122 |
processed_file = upload_and_process_file(temp_file.name)
|
123 |
content.append(processed_file)
|
124 |
|
|
|
125 |
# Send user entry to Gemini and read the response
|
126 |
-
response = model.generate_content(content)
|
|
|
127 |
|
128 |
-
#
|
129 |
-
st.session_state.chat.history.extend([
|
130 |
-
genai.types.Part(text=prompt, role="user"),
|
131 |
-
genai.types.Part(text=response.text, role="model"),
|
132 |
-
])
|
133 |
-
# Display last
|
134 |
with st.chat_message("assistant"):
|
135 |
st.markdown(response.text)
|
136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
except Exception as e:
|
138 |
st.error(f"An error occurred: {e}")
|
139 |
|
@@ -143,5 +146,4 @@ if prompt := st.chat_input("Hey?"):
|
|
143 |
try:
|
144 |
os.unlink(temp_file)
|
145 |
except Exception as e:
|
146 |
-
print(
|
147 |
-
f"Error deleting temporary file {temp_file}: {e}")
|
|
|
122 |
processed_file = upload_and_process_file(temp_file.name)
|
123 |
content.append(processed_file)
|
124 |
|
125 |
+
|
126 |
# Send user entry to Gemini and read the response
|
127 |
+
response = model.generate_content(content, stream=True)
|
128 |
+
response.resolve()
|
129 |
|
130 |
+
# Display the response
|
|
|
|
|
|
|
|
|
|
|
131 |
with st.chat_message("assistant"):
|
132 |
st.markdown(response.text)
|
133 |
|
134 |
+
# Update the chat history
|
135 |
+
st.session_state.chat.history.extend([
|
136 |
+
genai.types.Content(parts=[genai.types.Part(text=prompt)], role="user"),
|
137 |
+
genai.types.Content(parts=[genai.types.Part(text=response.text)], role="model")
|
138 |
+
])
|
139 |
+
|
140 |
except Exception as e:
|
141 |
st.error(f"An error occurred: {e}")
|
142 |
|
|
|
146 |
try:
|
147 |
os.unlink(temp_file)
|
148 |
except Exception as e:
|
149 |
+
print(f"Error deleting temporary file {temp_file}: {e}")
|
|