File size: 880 Bytes
162d73b
11f70a7
162d73b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import gradio as gr
from google import generativeai as genai
import textwrap

genai.configure(api_key="AIzaSyBrkmXQOKjOGXF9v_-URNa_3wmUZGaoSw0")

model = genai.GenerativeModel('models/gemini-1.5-flash')

def format_text(text):
    text = text.replace('•', '  ')
    return textwrap.indent(text, '> ', predicate=lambda _: True)

def analyze_image(image):
    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)
    response.resolve()
    return format_text(response.text)

interface = gr.Interface(
    fn=analyze_image,
    inputs=gr.Image(type="pil"),
    outputs=gr.Markdown(),  
    title="IngrediChef",
    description="Upload an Image of ingredients"
)

interface.launch('share=True')