vithacocf commited on
Commit
5a6435d
·
verified ·
1 Parent(s): 8d04804

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -6
app.py CHANGED
@@ -3,7 +3,8 @@ import tempfile
3
  import json
4
  import re
5
  import gradio as gr
6
- import google.generativeai as genai
 
7
 
8
  # ==== DEBUG VERSION ====
9
  print("Google Generative AI SDK version:", genai.__version__)
@@ -54,7 +55,10 @@ def process_image(image, prompt):
54
 
55
  # === API key rotation ===
56
  api_key = get_next_key()
57
- genai.configure(api_key=api_key)
 
 
 
58
 
59
  # === Ensure RAG store exists ===
60
  RAG_STORE_NAME = "default_rag_store"
@@ -76,7 +80,10 @@ def process_image(image, prompt):
76
  print(f"Created temp file: {temp_file}")
77
 
78
  # === Upload to Gemini with RAG ===
79
- uploaded_file = genai.upload_file(
 
 
 
80
  path=temp_file,
81
  display_name=os.path.basename(temp_file),
82
  mime_type="image/png",
@@ -88,10 +95,21 @@ def process_image(image, prompt):
88
  model = genai.GenerativeModel("gemini-2.5-flash")
89
 
90
  # === Generate content using RAG context ===
91
- response = model.generate_content(
92
- [prompt],
93
- request_options={"rag_store_name": RAG_STORE_NAME}, # cho phép truy vấn dựa theo store
 
 
 
 
 
 
 
 
 
 
94
  )
 
95
  print(f"Got response: {response.text[:200]}...")
96
 
97
  result = extract_json(response.text)
 
3
  import json
4
  import re
5
  import gradio as gr
6
+ # import google.generativeai as genai # Layton Luan - edit
7
+ from google import genai # Layton Luan - edit
8
 
9
  # ==== DEBUG VERSION ====
10
  print("Google Generative AI SDK version:", genai.__version__)
 
55
 
56
  # === API key rotation ===
57
  api_key = get_next_key()
58
+
59
+ # Layton Luan - edit
60
+ # genai.configure(api_key=api_key)
61
+ client = genai.Client(api_key=api_key)
62
 
63
  # === Ensure RAG store exists ===
64
  RAG_STORE_NAME = "default_rag_store"
 
80
  print(f"Created temp file: {temp_file}")
81
 
82
  # === Upload to Gemini with RAG ===
83
+
84
+ # Layton Luan - edit
85
+ # uploaded_file = genai.upload_file(
86
+ uploaded_file = client.files.upload(
87
  path=temp_file,
88
  display_name=os.path.basename(temp_file),
89
  mime_type="image/png",
 
95
  model = genai.GenerativeModel("gemini-2.5-flash")
96
 
97
  # === Generate content using RAG context ===
98
+
99
+ # Layton Luan - edit
100
+ # response = model.generate_content(
101
+ # [prompt],
102
+ # request_options={"rag_store_name": RAG_STORE_NAME}, # ✅ cho phép truy vấn dựa theo store
103
+ # )
104
+ response = client.models.generate_content(
105
+ model='gemini-2.0-flash',
106
+ contents=[
107
+ [prompt],
108
+ # request_options={"rag_store_name": RAG_STORE_NAME}, # ✅ cho phép truy vấn dựa theo store
109
+ uploaded_file
110
+ ]
111
  )
112
+
113
  print(f"Got response: {response.text[:200]}...")
114
 
115
  result = extract_json(response.text)