Spaces:
Sleeping
Sleeping
Commit
·
f96b00a
1
Parent(s):
acfddab
added gemini for description
Browse files
logs/access.log
CHANGED
|
@@ -1822,3 +1822,5 @@
|
|
| 1822 |
2025-11-14 15:21:29,402 | INFO | access_logger | app.py:20 | Response status: 200
|
| 1823 |
2025-11-14 15:21:38,172 | INFO | access_logger | app.py:18 | Request: POST http://127.0.0.1:8000/api/analytics-chatbot
|
| 1824 |
2025-11-14 15:21:39,030 | INFO | access_logger | app.py:20 | Response status: 200
|
|
|
|
|
|
|
|
|
| 1822 |
2025-11-14 15:21:29,402 | INFO | access_logger | app.py:20 | Response status: 200
|
| 1823 |
2025-11-14 15:21:38,172 | INFO | access_logger | app.py:18 | Request: POST http://127.0.0.1:8000/api/analytics-chatbot
|
| 1824 |
2025-11-14 15:21:39,030 | INFO | access_logger | app.py:20 | Response status: 200
|
| 1825 |
+
2025-11-14 15:34:22,638 | INFO | access_logger | app.py:18 | Request: POST http://127.0.0.1:8000/api/analytics-chatbot
|
| 1826 |
+
2025-11-14 15:34:30,193 | INFO | access_logger | app.py:20 | Response status: 200
|
requirements.txt
CHANGED
|
@@ -24,3 +24,4 @@ pytest==8.4.1
|
|
| 24 |
langchain_google_genai==2.1.9
|
| 25 |
mangum
|
| 26 |
redis==7.0.0
|
|
|
|
|
|
| 24 |
langchain_google_genai==2.1.9
|
| 25 |
mangum
|
| 26 |
redis==7.0.0
|
| 27 |
+
google-genai
|
src/genai/analytics_chatbot/handlers/analytics_description.py
CHANGED
|
@@ -1,31 +1,31 @@
|
|
| 1 |
-
|
| 2 |
-
from
|
| 3 |
import os
|
| 4 |
-
from
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def generate_analytics_description(query,image_base64):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
{
|
| 21 |
-
"type": "image_url",
|
| 22 |
-
"image_url": {
|
| 23 |
-
"url": f"data:image/jpeg;base64,{image_base64}"
|
| 24 |
-
}
|
| 25 |
-
}
|
| 26 |
-
]
|
| 27 |
-
}
|
| 28 |
-
],
|
| 29 |
)
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
return completion.choices[0].message.content
|
|
|
|
| 1 |
+
from google import genai
|
| 2 |
+
from google.genai import types
|
| 3 |
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
load_dotenv()
|
| 6 |
+
os.environ['GOOGLE_API_KEY']=os.getenv('GOOGLE_API_KEY')
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def analytics_description_prompt(query):
|
| 10 |
+
return f'''
|
| 11 |
+
You are provided with the user query and the image.
|
| 12 |
+
Give clear information to the user for their query only by analyzing the image. Don't give any responses outside of the image's context.
|
| 13 |
+
The user query is: \n{query}\n
|
| 14 |
+
'''
|
| 15 |
|
| 16 |
def generate_analytics_description(query,image_base64):
|
| 17 |
+
client = genai.Client()
|
| 18 |
+
response = client.models.generate_content(
|
| 19 |
+
model='gemini-2.5-flash',
|
| 20 |
+
contents=[
|
| 21 |
+
types.Part.from_bytes(
|
| 22 |
+
data=image_base64,
|
| 23 |
+
mime_type='image/jpeg',
|
| 24 |
+
),
|
| 25 |
+
analytics_description_prompt(query)
|
| 26 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
)
|
| 28 |
+
print('The image description:', response.text)
|
| 29 |
+
return response.text
|
| 30 |
+
|
| 31 |
|
|
|