Spaces:
Runtime error
Runtime error
Pranit commited on
Commit ·
16e2729
1
Parent(s): 9cbc2ea
app.py
CHANGED
|
@@ -31,7 +31,40 @@ if not api_key:
|
|
| 31 |
|
| 32 |
try:
|
| 33 |
genai.configure(api_key=api_key)
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# Test the connection
|
| 36 |
response = model.generate_content("Test connection")
|
| 37 |
logger.info("Successfully configured Gemini API")
|
|
@@ -289,7 +322,8 @@ def generate_content_with_retry(prompt, images):
|
|
| 289 |
response = model.generate_content(
|
| 290 |
[prompt] + images,
|
| 291 |
generation_config=genai.types.GenerationConfig(
|
| 292 |
-
timeout
|
|
|
|
| 293 |
)
|
| 294 |
)
|
| 295 |
return response
|
|
|
|
| 31 |
|
| 32 |
try:
|
| 33 |
genai.configure(api_key=api_key)
|
| 34 |
+
|
| 35 |
+
# Configure the model with safety settings
|
| 36 |
+
generation_config = {
|
| 37 |
+
"temperature": 0.9,
|
| 38 |
+
"top_p": 1,
|
| 39 |
+
"top_k": 1,
|
| 40 |
+
"max_output_tokens": 2048,
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
safety_settings = [
|
| 44 |
+
{
|
| 45 |
+
"category": "HARM_CATEGORY_HARASSMENT",
|
| 46 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"category": "HARM_CATEGORY_HATE_SPEECH",
|
| 50 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
| 54 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
| 58 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
| 59 |
+
}
|
| 60 |
+
]
|
| 61 |
+
|
| 62 |
+
model = genai.GenerativeModel(
|
| 63 |
+
model_name="gemini-1.5-flash",
|
| 64 |
+
generation_config=generation_config,
|
| 65 |
+
safety_settings=safety_settings
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
# Test the connection
|
| 69 |
response = model.generate_content("Test connection")
|
| 70 |
logger.info("Successfully configured Gemini API")
|
|
|
|
| 322 |
response = model.generate_content(
|
| 323 |
[prompt] + images,
|
| 324 |
generation_config=genai.types.GenerationConfig(
|
| 325 |
+
# Remove timeout parameter
|
| 326 |
+
# Other generation config parameters can be added here if needed
|
| 327 |
)
|
| 328 |
)
|
| 329 |
return response
|