Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,27 +14,34 @@ def snapchef_logic(image):
|
|
| 14 |
|
| 15 |
genai.configure(api_key=MY_API_KEY)
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
try:
|
| 18 |
-
#
|
| 19 |
model = genai.GenerativeModel('gemini-1.5-flash')
|
| 20 |
-
|
| 21 |
-
prompt = """
|
| 22 |
-
You are a Chef. Analyze this fridge photo.
|
| 23 |
-
1. List ingredients.
|
| 24 |
-
2. Suggest 1 Indian recipe.
|
| 25 |
-
3. Include 🇮🇳 Flag and YouTube Search Query.
|
| 26 |
-
"""
|
| 27 |
-
|
| 28 |
response = model.generate_content([prompt, image])
|
| 29 |
return response.text
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# --- APP UI ---
|
| 35 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 36 |
-
gr.Markdown("# 🍳 SnapChef AI
|
| 37 |
-
gr.Markdown("Created by Ajayadav • Powered by Gemini
|
| 38 |
|
| 39 |
with gr.Row():
|
| 40 |
img_input = gr.Image(type="pil", label="Upload Photo")
|
|
|
|
| 14 |
|
| 15 |
genai.configure(api_key=MY_API_KEY)
|
| 16 |
|
| 17 |
+
# SYSTEM INSTRUCTION: The Prompt
|
| 18 |
+
prompt = """
|
| 19 |
+
You are a Chef. Analyze this fridge photo.
|
| 20 |
+
1. List ingredients.
|
| 21 |
+
2. Suggest 1 Indian recipe.
|
| 22 |
+
3. Include 🇮🇳 Flag and YouTube Search Query.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
# --- SMART ENGINE: Try Newest -> Fallback to Oldest ---
|
| 26 |
try:
|
| 27 |
+
# Plan A: Try the fast Flash model
|
| 28 |
model = genai.GenerativeModel('gemini-1.5-flash')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
response = model.generate_content([prompt, image])
|
| 30 |
return response.text
|
| 31 |
+
except Exception as e_flash:
|
| 32 |
+
print(f"Flash failed: {e_flash}. Switching to backup...")
|
| 33 |
+
try:
|
| 34 |
+
# Plan B: Try the reliable 'gemini-pro' (Works everywhere)
|
| 35 |
+
model = genai.GenerativeModel('gemini-pro-vision')
|
| 36 |
+
response = model.generate_content([prompt, image])
|
| 37 |
+
return f"✅ (Backup Mode)\n\n{response.text}"
|
| 38 |
+
except Exception as e_backup:
|
| 39 |
+
return f"❌ CRITICAL ERROR: {e_backup}\n\nCheck your API Key in Settings!"
|
| 40 |
|
| 41 |
# --- APP UI ---
|
| 42 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 43 |
+
gr.Markdown("# 🍳 SnapChef AI")
|
| 44 |
+
gr.Markdown("Created by Ajayadav • Powered by Gemini")
|
| 45 |
|
| 46 |
with gr.Row():
|
| 47 |
img_input = gr.Image(type="pil", label="Upload Photo")
|