File size: 1,091 Bytes
bef155a
3dc74fc
bef155a
 
 
 
 
f526ffa
bef155a
 
 
 
 
 
 
 
 
 
 
f526ffa
bef155a
 
 
 
 
f526ffa
39c6037
0dc37ac
39c6037
4feaa93
0dc37ac
03bfe72
0dc37ac
f526ffa
bef155a
 
154c1fd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 = {"Images":["drums.jpg",
                               "desk.jpg",
                               "clown.png"],
                              "Text":["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()