Ajayadav commited on
Commit
195d5f2
·
verified ·
1 Parent(s): f0ef53f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import google.generativeai as genai
3
+ import os
4
+
5
+ # --- SECURITY: Load the key from the Vault ---
6
+ MY_API_KEY = os.environ.get("GEMINI_API_KEY")
7
+
8
+ def snapchef_logic(image):
9
+ if not MY_API_KEY:
10
+ return "⚠️ Error: API Key is missing. Please add GEMINI_API_KEY in Settings > Secrets."
11
+
12
+ if image is None:
13
+ return "⚠️ Please take a photo first!"
14
+
15
+ genai.configure(api_key=MY_API_KEY)
16
+
17
+ try:
18
+ # Using the standard model
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
+ except Exception as e:
32
+ return f"❌ Error: {e}"
33
+
34
+ # --- APP UI ---
35
+ with gr.Blocks(theme=gr.themes.Soft()) as app:
36
+ gr.Markdown("# 🍳 SnapChef AI (Official)")
37
+ gr.Markdown("Created by Ajayadav • Powered by Gemini AI")
38
+
39
+ with gr.Row():
40
+ img_input = gr.Image(type="pil", label="Upload Photo")
41
+ recipe_output = gr.Markdown(label="Chef's Recipe")
42
+
43
+ btn = gr.Button("Cook Something!", variant="primary")
44
+ btn.click(snapchef_logic, inputs=img_input, outputs=recipe_output)
45
+
46
+ app.launch()