Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -13,6 +13,9 @@ from google.generativeai.types import HarmCategory, HarmBlockThreshold
|
|
13 |
import google.ai.generativelanguage as glm
|
14 |
from PIL import Image
|
15 |
import io
|
|
|
|
|
|
|
16 |
|
17 |
from inference_sdk import InferenceHTTPClient
|
18 |
|
@@ -104,22 +107,7 @@ async def predict_wheat(image: UploadFile = File(...), model_id: str = "grian/1"
|
|
104 |
|
105 |
|
106 |
|
107 |
-
genai.configure(api_key="AIzaSyDReyKulYGTIj-8s-Nw38hGJDasjNpZhHA")
|
108 |
-
|
109 |
-
generation_config = {
|
110 |
-
"temperature": 1,
|
111 |
-
"top_p": 0.95,
|
112 |
-
"top_k": 64,
|
113 |
-
"max_output_tokens": 8192,
|
114 |
-
"response_mime_type": "text/plain",
|
115 |
-
}
|
116 |
|
117 |
-
safety_settings = {
|
118 |
-
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
|
119 |
-
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
|
120 |
-
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
|
121 |
-
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
|
122 |
-
}
|
123 |
|
124 |
def process_image(file: UploadFile):
|
125 |
image = Image.open(file.file)
|
@@ -142,6 +130,24 @@ def process_image(file: UploadFile):
|
|
142 |
|
143 |
@app.post("/analyze-image")
|
144 |
async def analyze_image(file: UploadFile = File(...)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
# Process the image
|
146 |
blob = process_image(file)
|
147 |
|
|
|
13 |
import google.ai.generativelanguage as glm
|
14 |
from PIL import Image
|
15 |
import io
|
16 |
+
import random
|
17 |
+
|
18 |
+
api_keys = os.getenv('GEMINI_API_KEYS').split(',')
|
19 |
|
20 |
from inference_sdk import InferenceHTTPClient
|
21 |
|
|
|
107 |
|
108 |
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
def process_image(file: UploadFile):
|
113 |
image = Image.open(file.file)
|
|
|
130 |
|
131 |
@app.post("/analyze-image")
|
132 |
async def analyze_image(file: UploadFile = File(...)):
|
133 |
+
selected_api_key = random.choice(api_keys)
|
134 |
+
print(f"Selected API Key: {selected_api_key}")
|
135 |
+
genai.configure(api_key=selected_api_key)
|
136 |
+
|
137 |
+
generation_config = {
|
138 |
+
"temperature": 1,
|
139 |
+
"top_p": 0.95,
|
140 |
+
"top_k": 64,
|
141 |
+
"max_output_tokens": 8192,
|
142 |
+
"response_mime_type": "text/plain",
|
143 |
+
}
|
144 |
+
|
145 |
+
safety_settings = {
|
146 |
+
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
|
147 |
+
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
|
148 |
+
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
|
149 |
+
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
|
150 |
+
}
|
151 |
# Process the image
|
152 |
blob = process_image(file)
|
153 |
|