Spaces:
Sleeping
Sleeping
Commit
·
a907c7b
1
Parent(s):
2fc1762
added secret
Browse files
app.py
CHANGED
|
@@ -2,18 +2,20 @@ import os
|
|
| 2 |
from google import genai
|
| 3 |
from PIL import Image
|
| 4 |
import gradio as gr
|
| 5 |
-
from
|
| 6 |
-
|
| 7 |
-
# Load environment variables
|
| 8 |
-
load_dotenv()
|
| 9 |
-
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def analyze_images(image1, image2):
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
chat = client.chats.create(model="gemini-2.0-flash")
|
| 18 |
|
| 19 |
try:
|
|
|
|
| 2 |
from google import genai
|
| 3 |
from PIL import Image
|
| 4 |
import gradio as gr
|
| 5 |
+
from huggingface_hub.secrets import get_secret
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def get_api_key():
|
| 8 |
+
try:
|
| 9 |
+
return get_secret('GEMINI_API_KEY')
|
| 10 |
+
except Exception as e:
|
| 11 |
+
return None
|
| 12 |
|
| 13 |
def analyze_images(image1, image2):
|
| 14 |
+
api_key = get_api_key()
|
| 15 |
+
if not api_key:
|
| 16 |
+
return "Error: GEMINI_API_KEY not found in HF Spaces secrets"
|
| 17 |
+
|
| 18 |
+
client = genai.Client(api_key=api_key)
|
| 19 |
chat = client.chats.create(model="gemini-2.0-flash")
|
| 20 |
|
| 21 |
try:
|