Spaces:
Sleeping
Sleeping
Gaurav vashistha
commited on
Commit
Β·
88ae637
1
Parent(s):
50e246b
Switch to Gemini Pro to bypass Flash 404 errors
Browse files- agents/visual_analyst.py +9 -9
agents/visual_analyst.py
CHANGED
|
@@ -14,23 +14,22 @@ class VisualAnalyst:
|
|
| 14 |
|
| 15 |
genai.configure(api_key=self.api_key)
|
| 16 |
|
| 17 |
-
|
| 18 |
-
print("π Checking available Gemini models for this key...")
|
| 19 |
try:
|
| 20 |
# Filter for models that support content generation
|
| 21 |
my_models = [m.name for m in genai.list_models() if 'generateContent' in m.supported_generation_methods]
|
| 22 |
print(f"π Available Models: {my_models}")
|
| 23 |
|
| 24 |
-
# UPDATED PRIORITY:
|
| 25 |
preferred_order = [
|
| 26 |
-
'models/gemini-1.5-
|
| 27 |
-
'models/gemini-1.5-flash', # Alias (Fallback)
|
| 28 |
'models/gemini-1.5-pro-001',
|
| 29 |
-
'models/gemini-1.5-
|
|
|
|
| 30 |
'models/gemini-pro-vision'
|
| 31 |
]
|
| 32 |
|
| 33 |
-
selected_model = "models/gemini-1.5-
|
| 34 |
|
| 35 |
for model_name in preferred_order:
|
| 36 |
if model_name in my_models:
|
|
@@ -41,8 +40,8 @@ class VisualAnalyst:
|
|
| 41 |
self.model = genai.GenerativeModel(selected_model)
|
| 42 |
|
| 43 |
except Exception as e:
|
| 44 |
-
print(f"β οΈ Model list failed ({e}), defaulting to gemini-1.5-
|
| 45 |
-
self.model = genai.GenerativeModel('gemini-1.5-
|
| 46 |
|
| 47 |
async def analyze_image(self, image_path: str):
|
| 48 |
# Adaptation: Read file path to bytes, as main.py passes a path
|
|
@@ -62,6 +61,7 @@ class VisualAnalyst:
|
|
| 62 |
"Return a JSON object with keys: main_color, product_type, design_style, visual_features."
|
| 63 |
)
|
| 64 |
try:
|
|
|
|
| 65 |
# Adaptation: Run in thread to allow async await
|
| 66 |
response = await asyncio.to_thread(
|
| 67 |
self.model.generate_content,
|
|
|
|
| 14 |
|
| 15 |
genai.configure(api_key=self.api_key)
|
| 16 |
|
| 17 |
+
print("π Checking available Gemini models...")
|
|
|
|
| 18 |
try:
|
| 19 |
# Filter for models that support content generation
|
| 20 |
my_models = [m.name for m in genai.list_models() if 'generateContent' in m.supported_generation_methods]
|
| 21 |
print(f"π Available Models: {my_models}")
|
| 22 |
|
| 23 |
+
# UPDATED PRIORITY: Force 'Pro' model to bypass Flash 404s
|
| 24 |
preferred_order = [
|
| 25 |
+
'models/gemini-1.5-pro', # <--- The Heavy Hitter (Smarter, diff backend)
|
|
|
|
| 26 |
'models/gemini-1.5-pro-001',
|
| 27 |
+
'models/gemini-1.5-flash',
|
| 28 |
+
'models/gemini-1.5-flash-001',
|
| 29 |
'models/gemini-pro-vision'
|
| 30 |
]
|
| 31 |
|
| 32 |
+
selected_model = "models/gemini-1.5-pro" # Default
|
| 33 |
|
| 34 |
for model_name in preferred_order:
|
| 35 |
if model_name in my_models:
|
|
|
|
| 40 |
self.model = genai.GenerativeModel(selected_model)
|
| 41 |
|
| 42 |
except Exception as e:
|
| 43 |
+
print(f"β οΈ Model list failed ({e}), defaulting to gemini-1.5-pro")
|
| 44 |
+
self.model = genai.GenerativeModel('gemini-1.5-pro')
|
| 45 |
|
| 46 |
async def analyze_image(self, image_path: str):
|
| 47 |
# Adaptation: Read file path to bytes, as main.py passes a path
|
|
|
|
| 61 |
"Return a JSON object with keys: main_color, product_type, design_style, visual_features."
|
| 62 |
)
|
| 63 |
try:
|
| 64 |
+
# Note: Pro model is sometimes stricter with image formats, but 'parts' usually works.
|
| 65 |
# Adaptation: Run in thread to allow async await
|
| 66 |
response = await asyncio.to_thread(
|
| 67 |
self.model.generate_content,
|