sudip2003 commited on
Commit
162d73b
·
verified ·
1 Parent(s): 7cdf8b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import google.generativeai as genai
3
+ import textwrap
4
+
5
+ genai.configure(api_key="AIzaSyBrkmXQOKjOGXF9v_-URNa_3wmUZGaoSw0")
6
+
7
+ model = genai.GenerativeModel('models/gemini-1.5-flash')
8
+
9
+ def format_text(text):
10
+ text = text.replace('•', ' ')
11
+ return textwrap.indent(text, '> ', predicate=lambda _: True)
12
+
13
+ def analyze_image(image):
14
+ response = model.generate_content(["Identify the ingredients in the image and suggest 5-10 popular dishes that can be made using most or all of these ingredients. For each dish, briefly list the main ingredients used.", image], stream=True)
15
+ response.resolve()
16
+ return format_text(response.text)
17
+
18
+ interface = gr.Interface(
19
+ fn=analyze_image,
20
+ inputs=gr.Image(type="pil"),
21
+ outputs=gr.Markdown(),
22
+ title="IngrediChef",
23
+ description="Upload an Image of ingredients"
24
+ )
25
+
26
+ interface.launch('share=True')