Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -64,9 +64,28 @@ Generated json
|
|
| 64 |
try:
|
| 65 |
genai.configure(api_key=api_key)
|
| 66 |
|
| 67 |
-
# Try
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
model_names = [
|
| 69 |
-
'gemini-
|
| 70 |
'gemini-1.5-pro',
|
| 71 |
'gemini-1.5-flash',
|
| 72 |
'gemini-1.0-pro'
|
|
@@ -80,22 +99,10 @@ Generated json
|
|
| 80 |
)
|
| 81 |
return f"β
Model initialized successfully! Using: {model_name}"
|
| 82 |
except Exception as model_error:
|
|
|
|
| 83 |
continue
|
| 84 |
|
| 85 |
-
|
| 86 |
-
models = genai.list_models()
|
| 87 |
-
available_models = [m.name for m in models if 'generateContent' in m.supported_generation_methods]
|
| 88 |
-
|
| 89 |
-
if available_models:
|
| 90 |
-
# Use the first available model
|
| 91 |
-
model_name = available_models[0].replace('models/', '')
|
| 92 |
-
self.model = genai.GenerativeModel(
|
| 93 |
-
model_name=model_name,
|
| 94 |
-
system_instruction=self.SYSTEM_PROMPT
|
| 95 |
-
)
|
| 96 |
-
return f"β
Model initialized successfully! Using: {model_name}"
|
| 97 |
-
else:
|
| 98 |
-
return "β No compatible models found"
|
| 99 |
|
| 100 |
except Exception as e:
|
| 101 |
return f"β Error initializing model: {str(e)}"
|
|
@@ -107,7 +114,7 @@ Generated json
|
|
| 107 |
|
| 108 |
if not self.model:
|
| 109 |
init_result = self.initialize_model(api_key)
|
| 110 |
-
if "Error" in init_result:
|
| 111 |
return None, None, init_result
|
| 112 |
|
| 113 |
if not core_prompt.strip():
|
|
|
|
| 64 |
try:
|
| 65 |
genai.configure(api_key=api_key)
|
| 66 |
|
| 67 |
+
# Try to list available models first
|
| 68 |
+
try:
|
| 69 |
+
models = genai.list_models()
|
| 70 |
+
available_models = [m.name for m in models if 'generateContent' in m.supported_generation_methods]
|
| 71 |
+
|
| 72 |
+
# Print available models for debugging
|
| 73 |
+
print(f"Available models: {available_models}")
|
| 74 |
+
|
| 75 |
+
if available_models:
|
| 76 |
+
# Extract just the model name without the prefix
|
| 77 |
+
model_name = available_models[0].split('/')[-1]
|
| 78 |
+
self.model = genai.GenerativeModel(
|
| 79 |
+
model_name=model_name,
|
| 80 |
+
system_instruction=self.SYSTEM_PROMPT
|
| 81 |
+
)
|
| 82 |
+
return f"β
Model initialized successfully! Using: {model_name}"
|
| 83 |
+
except Exception as list_error:
|
| 84 |
+
print(f"Error listing models: {list_error}")
|
| 85 |
+
|
| 86 |
+
# If listing models fails, try these specific models
|
| 87 |
model_names = [
|
| 88 |
+
'gemini-pro',
|
| 89 |
'gemini-1.5-pro',
|
| 90 |
'gemini-1.5-flash',
|
| 91 |
'gemini-1.0-pro'
|
|
|
|
| 99 |
)
|
| 100 |
return f"β
Model initialized successfully! Using: {model_name}"
|
| 101 |
except Exception as model_error:
|
| 102 |
+
print(f"Error with model {model_name}: {model_error}")
|
| 103 |
continue
|
| 104 |
|
| 105 |
+
return "β No compatible models found. Please check your API key and available models."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
except Exception as e:
|
| 108 |
return f"β Error initializing model: {str(e)}"
|
|
|
|
| 114 |
|
| 115 |
if not self.model:
|
| 116 |
init_result = self.initialize_model(api_key)
|
| 117 |
+
if "Error" in init_result or "β" in init_result:
|
| 118 |
return None, None, init_result
|
| 119 |
|
| 120 |
if not core_prompt.strip():
|