Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,34 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
return
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
30 |
|
31 |
app.launch()
|
|
|
|
|
|
1 |
+
import google.generativeai as genai
|
2 |
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
+
import PIL.Image
|
5 |
+
|
6 |
+
genai.configure(api_key="AIzaSyAj-b3sO_wUguMdpXWScxKzMHxb8C5cels")
|
7 |
+
|
8 |
+
def ImageChat(image):
|
9 |
+
|
10 |
+
# load model
|
11 |
+
model = genai.GenerativeModel("gemini-pro-vision")
|
12 |
+
|
13 |
+
# check image file and convert to a Numpy array
|
14 |
+
if isinstance(image, np.ndarray):
|
15 |
+
|
16 |
+
img = PIL.Image.fromarray(image)
|
17 |
+
else:
|
18 |
+
img = PIL.Image.open(image)
|
19 |
+
|
20 |
+
response = model.generate_content(["write a short, exciting, captivating, and funny adventure story about the image", img])
|
21 |
+
|
22 |
+
return response.text
|
23 |
+
|
24 |
+
|
25 |
+
app = gr.Interface(ImageChat,
|
26 |
+
inputs = gr.Image(),
|
27 |
+
outputs = gr.Text(),
|
28 |
+
title = "Image-To-Story",
|
29 |
+
theme = gr.themes.Soft())
|
30 |
+
|
31 |
|
32 |
app.launch()
|
33 |
+
|
34 |
+
|