Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,10 +10,25 @@ if not api_key:
|
|
| 10 |
else:
|
| 11 |
genai.configure(api_key=api_key)
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def gemini_generate(prompt):
|
| 14 |
-
"""Generate content using the Gemini model with
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
class GeminiAgent:
|
| 19 |
"""A simple agent wrapper that uses the Gemini model for generating responses."""
|
|
@@ -97,7 +112,7 @@ else:
|
|
| 97 |
)
|
| 98 |
return combined_response
|
| 99 |
|
| 100 |
-
st.title("
|
| 101 |
st.write(
|
| 102 |
"Ask any question related to schools, colleges, or universities in underserved regions. "
|
| 103 |
"The chatbot will analyze the challenges, propose actionable solutions, and provide examples of institutions when relevant."
|
|
|
|
| 10 |
else:
|
| 11 |
genai.configure(api_key=api_key)
|
| 12 |
|
| 13 |
+
# Get available models
|
| 14 |
+
try:
|
| 15 |
+
available_models = [model.name for model in genai.list_models()]
|
| 16 |
+
if "gemini-pro" not in available_models:
|
| 17 |
+
st.warning(f"'gemini-pro' not found. Using 'gemini-pro-latest' instead.")
|
| 18 |
+
model_name = "gemini-pro-latest"
|
| 19 |
+
else:
|
| 20 |
+
model_name = "gemini-pro"
|
| 21 |
+
except Exception as e:
|
| 22 |
+
st.error(f"Error fetching available models: {e}")
|
| 23 |
+
model_name = "gemini-pro-latest"
|
| 24 |
+
|
| 25 |
def gemini_generate(prompt):
|
| 26 |
+
"""Generate content using the Gemini model with error handling."""
|
| 27 |
+
try:
|
| 28 |
+
response = genai.GenerativeModel(model_name).generate_content(prompt)
|
| 29 |
+
return response.text
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return f"Error generating response: {e}"
|
| 32 |
|
| 33 |
class GeminiAgent:
|
| 34 |
"""A simple agent wrapper that uses the Gemini model for generating responses."""
|
|
|
|
| 112 |
)
|
| 113 |
return combined_response
|
| 114 |
|
| 115 |
+
st.title("EduConnect Underserved Institutions Chatbot")
|
| 116 |
st.write(
|
| 117 |
"Ask any question related to schools, colleges, or universities in underserved regions. "
|
| 118 |
"The chatbot will analyze the challenges, propose actionable solutions, and provide examples of institutions when relevant."
|