Spaces:
Sleeping
Sleeping
Commit
·
bb3134a
1
Parent(s):
c51708f
next
Browse files
api/routers/analytics_chatbot.py
CHANGED
|
@@ -53,7 +53,8 @@ def get_analytics(request: AnalyticsChatRequest):
|
|
| 53 |
|
| 54 |
if request.image_base64 and not response_to_cache.get('description'):
|
| 55 |
description = generate_analytics_description(user_query, request.image_base64)
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
redis_client.set(cache_key, json.dumps(response_to_cache), ex=3000)
|
| 59 |
return response_to_cache
|
|
|
|
| 53 |
|
| 54 |
if request.image_base64 and not response_to_cache.get('description'):
|
| 55 |
description = generate_analytics_description(user_query, request.image_base64)
|
| 56 |
+
if description is not None:
|
| 57 |
+
response_to_cache['description'] = description
|
| 58 |
|
| 59 |
redis_client.set(cache_key, json.dumps(response_to_cache), ex=3000)
|
| 60 |
return response_to_cache
|
src/genai/analytics_chatbot/handlers/analytics_description.py
CHANGED
|
@@ -15,19 +15,21 @@ os.environ['GOOGLE_API_KEY']=os.getenv('GOOGLE_API_KEY')
|
|
| 15 |
# '''
|
| 16 |
|
| 17 |
def generate_analytics_description(query,image_base64):
|
| 18 |
-
if image_base64
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
|
|
|
|
| 15 |
# '''
|
| 16 |
|
| 17 |
def generate_analytics_description(query,image_base64):
|
| 18 |
+
if image_base64=='string':
|
| 19 |
+
return None
|
| 20 |
+
client = genai.Client()
|
| 21 |
+
response = client.models.generate_content(
|
| 22 |
+
model='gemini-2.5-flash',
|
| 23 |
+
contents=[
|
| 24 |
+
types.Part.from_bytes(
|
| 25 |
+
data=image_base64,
|
| 26 |
+
mime_type='image/jpeg',
|
| 27 |
+
),
|
| 28 |
+
analytics_description_prompt(query)
|
| 29 |
+
]
|
| 30 |
+
)
|
| 31 |
+
print('The image description:', response.text)
|
| 32 |
+
return response.text
|
| 33 |
+
|
| 34 |
|
| 35 |
|