Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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="AIzaSyA7tPavobVN5_3-BJ0qhFT5HVjO4V19QWk")
|
| 7 |
+
|
| 8 |
+
def ImageChat(image, prompt):
|
| 9 |
+
|
| 10 |
+
# load model
|
| 11 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 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([prompt, img])
|
| 21 |
+
|
| 22 |
+
return response.text
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
app = gr.Interface(ImageChat,
|
| 26 |
+
inputs = [gr.Image(label = "Image"), gr.Text(label = "Prompt")],
|
| 27 |
+
outputs = gr.Text(label = "Response"),
|
| 28 |
+
title = "Image Chat",
|
| 29 |
+
theme = "Taithrah/Minimal")
|
| 30 |
+
|
| 31 |
+
app.launch()
|