Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,10 +24,7 @@ def get_api_key_from_secrets():
|
|
24 |
"""Try to get API key from HuggingFace secrets or environment variables"""
|
25 |
# Try multiple possible secret names
|
26 |
possible_keys = [
|
27 |
-
'
|
28 |
-
'GEMINI_API_KEY',
|
29 |
-
'GOOGLE_GEMINI_API_KEY',
|
30 |
-
'GOOGLE_AI_API_KEY'
|
31 |
]
|
32 |
|
33 |
for key_name in possible_keys:
|
@@ -61,39 +58,15 @@ def setup_gemini(api_key: str = None):
|
|
61 |
API_KEY = get_api_key_from_secrets()
|
62 |
|
63 |
if not API_KEY:
|
64 |
-
return False, "β No API key found. Please:\n1. Set GOOGLE_API_KEY in HuggingFace Spaces secrets
|
65 |
|
66 |
try:
|
67 |
# Configure the API
|
68 |
genai.configure(api_key=API_KEY)
|
69 |
|
70 |
-
# Initialize the model with safety settings
|
71 |
-
safety_settings = [
|
72 |
-
{
|
73 |
-
"category": "HARM_CATEGORY_MEDICAL",
|
74 |
-
"threshold": "BLOCK_NONE"
|
75 |
-
},
|
76 |
-
{
|
77 |
-
"category": "HARM_CATEGORY_HARASSMENT",
|
78 |
-
"threshold": "BLOCK_ONLY_HIGH"
|
79 |
-
},
|
80 |
-
{
|
81 |
-
"category": "HARM_CATEGORY_HATE_SPEECH",
|
82 |
-
"threshold": "BLOCK_ONLY_HIGH"
|
83 |
-
},
|
84 |
-
{
|
85 |
-
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
86 |
-
"threshold": "BLOCK_ONLY_HIGH"
|
87 |
-
},
|
88 |
-
{
|
89 |
-
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
90 |
-
"threshold": "BLOCK_ONLY_HIGH"
|
91 |
-
}
|
92 |
-
]
|
93 |
|
94 |
GEMINI_MODEL = genai.GenerativeModel(
|
95 |
-
'gemini-1.5-pro'
|
96 |
-
safety_settings=safety_settings
|
97 |
)
|
98 |
|
99 |
# Test the connection with a simple query
|
@@ -401,7 +374,7 @@ def create_interface():
|
|
401 |
if initial_api_key:
|
402 |
gr.Markdown("""
|
403 |
### β
API Key Found in Secrets
|
404 |
-
An API key was found in the environment/secrets.
|
405 |
""")
|
406 |
else:
|
407 |
gr.Markdown("""
|
|
|
24 |
"""Try to get API key from HuggingFace secrets or environment variables"""
|
25 |
# Try multiple possible secret names
|
26 |
possible_keys = [
|
27 |
+
'GEMINI_API_KEY'
|
|
|
|
|
|
|
28 |
]
|
29 |
|
30 |
for key_name in possible_keys:
|
|
|
58 |
API_KEY = get_api_key_from_secrets()
|
59 |
|
60 |
if not API_KEY:
|
61 |
+
return False, "β No API key found. Please:\n1. Set GOOGLE_API_KEY in HuggingFace Spaces secrets"
|
62 |
|
63 |
try:
|
64 |
# Configure the API
|
65 |
genai.configure(api_key=API_KEY)
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
GEMINI_MODEL = genai.GenerativeModel(
|
69 |
+
'gemini-1.5-pro'
|
|
|
70 |
)
|
71 |
|
72 |
# Test the connection with a simple query
|
|
|
374 |
if initial_api_key:
|
375 |
gr.Markdown("""
|
376 |
### β
API Key Found in Secrets
|
377 |
+
An API key was found in the environment/secrets.
|
378 |
""")
|
379 |
else:
|
380 |
gr.Markdown("""
|