Spaces:
Running
Running
import google.generativeai as genai | |
import gradio as gr | |
import numpy as np | |
import PIL.Image | |
genai.configure(api_key="AIzaSyA7tPavobVN5_3-BJ0qhFT5HVjO4V19QWk") | |
def ImageChat(image): | |
# load model | |
model = genai.GenerativeModel("gemini-1.5-flash") | |
# 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(["write a short story about the image", img]) | |
return response.text | |
app = gr.Interface(ImageChat, | |
inputs = gr.Image(label = "Image"), | |
outputs = gr.Text(label = "Story"), | |
examples = ["rubiks cube.jpg","giraffe.jpg","street.jpg"], | |
title = "Image-To-Story", | |
theme = "patrickosornio/my_theme1") | |
app.launch() | |