Spaces:
Runtime error
Runtime error
Commit
·
2c99da2
1
Parent(s):
8b103fc
Update app.py
Browse files
app.py
CHANGED
@@ -144,26 +144,25 @@ if user_input:
|
|
144 |
max_output_tokens=max_output_tokens,
|
145 |
# add other settings if needed
|
146 |
)
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
return
|
167 |
|
168 |
# Add model response to chat history
|
169 |
st.session_state["chat_history"].append({"role": "model", "parts": [{"text": response}]})
|
|
|
144 |
max_output_tokens=max_output_tokens,
|
145 |
# add other settings if needed
|
146 |
)
|
147 |
+
# Generate model response
|
148 |
+
try:
|
149 |
+
if model_name == "gemini-pro":
|
150 |
+
model = genai.GenerativeModel('gemini-pro')
|
151 |
+
response = model.generate_content(
|
152 |
+
contents=[user_input],
|
153 |
+
generation_config=generation_config
|
154 |
+
)
|
155 |
+
elif model_name == "gemini-pro-vision":
|
156 |
+
images = [Image.open(file).convert('RGB') for file in uploaded_files]
|
157 |
+
image_prompts = [{'mime_type': 'image/png', 'data': image.tobytes()} for image in images]
|
158 |
+
model = genai.GenerativeModel('gemini-pro-vision')
|
159 |
+
response = model.generate_content(
|
160 |
+
contents=[user_input] + image_prompts,
|
161 |
+
generation_config=generation_config
|
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}]})
|