Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import google.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') |