Image-Chat / app.py
Ifeanyi's picture
Update app.py
03bfe72 verified
raw
history blame
1.08 kB
import google.generativeai as genai
import gradio as gr
import numpy as np
import PIL.Image
genai.configure(api_key="AIzaSyAj-b3sO_wUguMdpXWScxKzMHxb8C5cels")
def ImageChat(image, prompt):
# load model
model = genai.GenerativeModel("gemini-pro-vision")
# check image file and convert to a Numpy array
if isinstance(image, np.ndarray):
img = PIL.Image.fromarray(image)
else:
img = PIL.Image.open(image)
response = model.generate_content([prompt, img])
return response.text
app = gr.Interface(ImageChat,
inputs = [gr.Image(), gr.Text()],
outputs = gr.Text(label = "Chat"),
examples = [["drums.jpg",
"desk.jpg",
"clown.png"],
["What is this image about?",
"List the items in this image",
"Give me 5 facts about this image."]],
title = "Image Chat",
theme = gr.themes.Soft())
app.launch()