|
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): |
|
|
|
|
|
model = genai.GenerativeModel("gemini-pro-vision") |
|
|
|
|
|
if isinstance(image, np.ndarray): |
|
|
|
img = PIL.Image.fromarray(image) |
|
else: |
|
img = PIL.Image.open(image) |
|
|
|
response = model.generate_content(["write a short, exciting, captivating, and funny adventure story about the image", img]) |
|
|
|
return response.text |
|
|
|
|
|
app = gr.Interface(ImageChat, |
|
inputs = gr.Image(), |
|
outputs = gr.Text(), |
|
title = "Image-To-Story", |
|
theme = gr.themes.Soft()) |
|
|
|
|
|
app.launch() |
|
|
|
|
|
|