Spaces:
Sleeping
Sleeping
Commit
·
c51708f
1
Parent(s):
f96b00a
fixed validation
Browse files
src/genai/analytics_chatbot/handlers/analytics_description.py
CHANGED
|
@@ -1,31 +1,33 @@
|
|
| 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 |
-
|
| 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 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
|
|
|
|
| 1 |
from google import genai
|
| 2 |
from google.genai import types
|
| 3 |
import os
|
| 4 |
+
from ..utils.prompts import analytics_description_prompt
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
load_dotenv()
|
| 7 |
os.environ['GOOGLE_API_KEY']=os.getenv('GOOGLE_API_KEY')
|
| 8 |
|
| 9 |
|
| 10 |
+
# def analytics_description_prompt(query):
|
| 11 |
+
# return f'''
|
| 12 |
+
# You are provided with the user query and the image.
|
| 13 |
+
# 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.
|
| 14 |
+
# The user query is: \n{query}\n
|
| 15 |
+
# '''
|
| 16 |
|
| 17 |
def generate_analytics_description(query,image_base64):
|
| 18 |
+
if image_base64 != 'string':
|
| 19 |
+
client = genai.Client()
|
| 20 |
+
response = client.models.generate_content(
|
| 21 |
+
model='gemini-2.5-flash',
|
| 22 |
+
contents=[
|
| 23 |
+
types.Part.from_bytes(
|
| 24 |
+
data=image_base64,
|
| 25 |
+
mime_type='image/jpeg',
|
| 26 |
+
),
|
| 27 |
+
analytics_description_prompt(query)
|
| 28 |
+
]
|
| 29 |
+
)
|
| 30 |
+
print('The image description:', response.text)
|
| 31 |
+
return response.text
|
| 32 |
|
| 33 |
|