Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,30 +2,48 @@ 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
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 |
-
|
18 |
img = PIL.Image.open(image)
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
|
|
23 |
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
30 |
|
31 |
-
app.launch()
|
|
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
import PIL.Image
|
5 |
+
import pandas as pd
|
6 |
|
7 |
genai.configure(api_key="AIzaSyA7tPavobVN5_3-BJ0qhFT5HVjO4V19QWk")
|
8 |
|
9 |
+
def ImageChat(image):
|
10 |
+
# Lista de preguntas preconfiguradas
|
11 |
+
questions = [
|
12 |
+
"¿La persona está utilizando auriculares?",
|
13 |
+
"¿La persona está utilizando capucha o algo que le cubra la cabeza?",
|
14 |
+
"¿Existe dinero como monedas o billetes que estén el piso?",
|
15 |
+
"¿La persona se encuentra interactuando con su teléfono móvil?"
|
16 |
+
]
|
17 |
|
18 |
+
# load model
|
19 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
|
|
|
|
|
|
20 |
|
21 |
+
# check image file and convert to a Numpy array
|
22 |
+
if isinstance(image, np.ndarray):
|
23 |
img = PIL.Image.fromarray(image)
|
24 |
+
else:
|
25 |
img = PIL.Image.open(image)
|
26 |
|
27 |
+
# Initialize results list
|
28 |
+
results = []
|
29 |
+
|
30 |
+
# Process each question
|
31 |
+
for question in questions:
|
32 |
+
response = model.generate_content([question, img])
|
33 |
+
results.append(response.text)
|
34 |
|
35 |
+
# Create a DataFrame to display results as a table
|
36 |
+
df = pd.DataFrame({"Pregunta": questions, "Respuesta": results})
|
37 |
|
38 |
+
return df
|
39 |
|
40 |
+
# Define Gradio interface
|
41 |
+
app = gr.Interface(
|
42 |
+
ImageChat,
|
43 |
+
inputs=gr.Image(label="Imagen"),
|
44 |
+
outputs=gr.Dataframe(headers=["Pregunta", "Respuesta"], label="Resultados"),
|
45 |
+
title="Análisis de Imagen",
|
46 |
+
theme="Taithrah/Minimal"
|
47 |
+
)
|
48 |
|
49 |
+
app.launch()
|