Docfile's picture
Update app.py
5fedf9f verified
raw
history blame
1.01 kB
import gradio as gr
import google.generativeai as genai
from IPython.display import Markdown
import textwrap
def to_markdown(text):
if text is not None:
text = text.replace('•', ' *')
return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
else:
return Markdown("No response received.")
token = "AIzaSyDYhyRoOWBJWOb4bqY5wmFLrBo4HTwQDko"
genai.configure(api_key=token)
# Chargez l'image
model = genai.GenerativeModel(model_name="gemini-pro-vision")
# Fonction pour générer le contenu
def generate_content(image):
response = model.generate_content(["Write a short, engaging blog post based on this picture. It should include a description of the meal in the photo and talk about my journey meal prepping.", image], stream=True)
markdown_response = to_markdown(response.resolve())
return markdown_response
# Interface Gradio
iface = gr.Interface(fn=generate_content, inputs=gr.Image(type='pil'), outputs="text")
iface.launch(share=True)