Spaces:
Sleeping
Sleeping
Gaurav vashistha
commited on
Commit
·
9d3f2ae
1
Parent(s):
3a6f5ad
Update dependencies and fix gemini model version
Browse files- agents/visual_analyst.py +9 -20
- requirements.txt +1 -1
agents/visual_analyst.py
CHANGED
|
@@ -10,10 +10,10 @@ class VisualAnalyst:
|
|
| 10 |
def __init__(self):
|
| 11 |
self.api_key = os.getenv("GEMINI_API_KEY")
|
| 12 |
if not self.api_key:
|
| 13 |
-
raise ValueError("GEMINI_API_KEY not found
|
| 14 |
genai.configure(api_key=self.api_key)
|
| 15 |
-
# UPDATED: Using
|
| 16 |
-
self.model = genai.GenerativeModel('gemini-1.5-flash')
|
| 17 |
|
| 18 |
async def analyze_image(self, image_path: str):
|
| 19 |
# Read file as bytes to match the user's logic requirements
|
|
@@ -30,9 +30,7 @@ class VisualAnalyst:
|
|
| 30 |
|
| 31 |
prompt = (
|
| 32 |
"Analyze this product image for an e-commerce listing. "
|
| 33 |
-
"
|
| 34 |
-
"and 3 distinct Visual Features. Return the result strictly as a JSON object "
|
| 35 |
-
"with keys: main_color, product_type, design_style, visual_features."
|
| 36 |
)
|
| 37 |
|
| 38 |
try:
|
|
@@ -45,23 +43,14 @@ class VisualAnalyst:
|
|
| 45 |
]
|
| 46 |
)
|
| 47 |
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
-
if text_response.startswith('```json'):
|
| 52 |
-
text_response = text_response[7:]
|
| 53 |
-
if text_response.startswith('```'):
|
| 54 |
-
text_response = text_response[3:]
|
| 55 |
-
if text_response.endswith('```'):
|
| 56 |
-
text_response = text_response[:-3]
|
| 57 |
-
|
| 58 |
-
return json.loads(text_response.strip())
|
| 59 |
except Exception as e:
|
| 60 |
-
print(f"⚠️ API Error: {e}")
|
| 61 |
-
# Return a clearer error for debugging
|
| 62 |
return {
|
| 63 |
"main_color": "Unknown",
|
| 64 |
-
"product_type": "Unidentified Item",
|
| 65 |
-
"design_style": "Standard",
|
| 66 |
"visual_features": [f"Error: {str(e)}"]
|
| 67 |
}
|
|
|
|
| 10 |
def __init__(self):
|
| 11 |
self.api_key = os.getenv("GEMINI_API_KEY")
|
| 12 |
if not self.api_key:
|
| 13 |
+
raise ValueError("GEMINI_API_KEY not found")
|
| 14 |
genai.configure(api_key=self.api_key)
|
| 15 |
+
# UPDATED: Using specific version ID to avoid 404s
|
| 16 |
+
self.model = genai.GenerativeModel('gemini-1.5-flash-001')
|
| 17 |
|
| 18 |
async def analyze_image(self, image_path: str):
|
| 19 |
# Read file as bytes to match the user's logic requirements
|
|
|
|
| 30 |
|
| 31 |
prompt = (
|
| 32 |
"Analyze this product image for an e-commerce listing. "
|
| 33 |
+
"Return a JSON object with keys: main_color, product_type, design_style, visual_features."
|
|
|
|
|
|
|
| 34 |
)
|
| 35 |
|
| 36 |
try:
|
|
|
|
| 43 |
]
|
| 44 |
)
|
| 45 |
|
| 46 |
+
text = response.text
|
| 47 |
+
# Clean markdown
|
| 48 |
+
if text.startswith('```json'): text = text[7:]
|
| 49 |
+
if text.endswith('```'): text = text[:-3]
|
| 50 |
|
| 51 |
+
return json.loads(text.strip())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
except Exception as e:
|
|
|
|
|
|
|
| 53 |
return {
|
| 54 |
"main_color": "Unknown",
|
|
|
|
|
|
|
| 55 |
"visual_features": [f"Error: {str(e)}"]
|
| 56 |
}
|
requirements.txt
CHANGED
|
@@ -8,6 +8,6 @@ langchain-groq
|
|
| 8 |
pinecone>=3.0.0
|
| 9 |
pydantic
|
| 10 |
python-dotenv
|
| 11 |
-
google-generativeai
|
| 12 |
groq
|
| 13 |
Pillow
|
|
|
|
| 8 |
pinecone>=3.0.0
|
| 9 |
pydantic
|
| 10 |
python-dotenv
|
| 11 |
+
google-generativeai>=0.7.2
|
| 12 |
groq
|
| 13 |
Pillow
|