Update app.py
Browse files
app.py
CHANGED
@@ -195,7 +195,7 @@ with st.sidebar:
|
|
195 |
|
196 |
model_name = st.selectbox(
|
197 |
"Select Model",
|
198 |
-
["gemini-2.0-pro-exp-02-05", "gemini-exp-1206", "gemini-2.0-flash-lite-preview-02-05", "gemini-1.5-pro", "gemini-2.0-flash-exp", "gemini-2.0-flash-thinking-exp-1219"]
|
199 |
)
|
200 |
|
201 |
temperature = st.slider(
|
@@ -224,6 +224,7 @@ with st.sidebar:
|
|
224 |
|
225 |
api_key = "AIzaSyB93eoXaU48hrJ2hojk-2gQPj28dGVSIbQ"
|
226 |
backup_api_key = "AIzaSyDNWizNQAA0UaflR5f_zTF6FcMSIA5D8RU"
|
|
|
227 |
|
228 |
genai.configure(api_key=api_key)
|
229 |
|
@@ -254,17 +255,29 @@ if st.button("Generate"):
|
|
254 |
except Exception as e:
|
255 |
if "429" in str(e):
|
256 |
try:
|
257 |
-
# Switch to backup API key
|
258 |
genai.configure(api_key=backup_api_key)
|
259 |
model = genai.GenerativeModel(
|
260 |
model_name=model_name,
|
261 |
generation_config=generation_config,
|
262 |
)
|
263 |
-
# Retry with
|
264 |
response = model.generate_content(prompt)
|
265 |
output = response.text.strip()
|
266 |
st.success(f"Output: {output}")
|
267 |
except Exception as backup_error:
|
268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
else:
|
270 |
st.error(f"An error occurred: {str(e)}")
|
|
|
195 |
|
196 |
model_name = st.selectbox(
|
197 |
"Select Model",
|
198 |
+
["gemini-2.0-pro-exp-02-05", "gemini-exp-1206", "gemini-2.0-flash-lite-preview-02-05", "gemini-1.5-pro", "gemini-2.0-flash-exp", "gemini-2.0-flash-thinking-exp-1219", "learnlm-1.5-pro-experimental"]
|
199 |
)
|
200 |
|
201 |
temperature = st.slider(
|
|
|
224 |
|
225 |
api_key = "AIzaSyB93eoXaU48hrJ2hojk-2gQPj28dGVSIbQ"
|
226 |
backup_api_key = "AIzaSyDNWizNQAA0UaflR5f_zTF6FcMSIA5D8RU"
|
227 |
+
backup_api_key_2 = "AIzaSyCrhuU-XT142KWB_zmA807qeJcE0dEjeJw"
|
228 |
|
229 |
genai.configure(api_key=api_key)
|
230 |
|
|
|
255 |
except Exception as e:
|
256 |
if "429" in str(e):
|
257 |
try:
|
258 |
+
# Switch to first backup API key
|
259 |
genai.configure(api_key=backup_api_key)
|
260 |
model = genai.GenerativeModel(
|
261 |
model_name=model_name,
|
262 |
generation_config=generation_config,
|
263 |
)
|
264 |
+
# Retry with first backup API key
|
265 |
response = model.generate_content(prompt)
|
266 |
output = response.text.strip()
|
267 |
st.success(f"Output: {output}")
|
268 |
except Exception as backup_error:
|
269 |
+
try:
|
270 |
+
# Switch to second backup API key
|
271 |
+
genai.configure(api_key=backup_api_key_2)
|
272 |
+
model = genai.GenerativeModel(
|
273 |
+
model_name=model_name,
|
274 |
+
generation_config=generation_config,
|
275 |
+
)
|
276 |
+
# Retry with second backup API key
|
277 |
+
response = model.generate_content(prompt)
|
278 |
+
output = response.text.strip()
|
279 |
+
st.success(f"Output: {output}")
|
280 |
+
except Exception as backup_error_2:
|
281 |
+
st.error(f"Error with both backup API keys: {str(backup_error_2)}")
|
282 |
else:
|
283 |
st.error(f"An error occurred: {str(e)}")
|