Spaces:
Sleeping
Sleeping
sandrocalzada
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -45,21 +45,44 @@ def ImageChat(image):
|
|
45 |
|
46 |
return df
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
# Define Gradio interface
|
49 |
-
|
50 |
-
(
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
|
57 |
app = gr.Interface(
|
58 |
-
ImageChat,
|
59 |
-
inputs=
|
60 |
outputs=gr.Dataframe(headers=["Pregunta", "Respuesta"], label="Resultados"),
|
61 |
title="Análisis de Imagen",
|
62 |
theme="Taithrah/Minimal"
|
63 |
)
|
64 |
|
65 |
-
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
return df
|
47 |
|
48 |
+
def load_image(image_path):
|
49 |
+
with open(image_path, "rb") as image_file:
|
50 |
+
return image_file.read()
|
51 |
+
|
52 |
+
# Preloaded images
|
53 |
+
preloaded_images = {
|
54 |
+
"Imagen Ejemplo 1": "chat_with_image.png",
|
55 |
+
"Imagen Ejemplo 2": "chatwithimg_2.jpg",
|
56 |
+
"Imagen Ejemplo 3": "chatwithimg3.png"
|
57 |
+
}
|
58 |
+
|
59 |
+
def get_selected_image(image_name):
|
60 |
+
return load_image(preloaded_images[image_name])
|
61 |
+
|
62 |
# Define Gradio interface
|
63 |
+
image_selector = gr.Radio(
|
64 |
+
choices=list(preloaded_images.keys()),
|
65 |
+
label="Selecciona una imagen"
|
66 |
+
)
|
67 |
+
|
68 |
+
image_display = gr.Image(label="Imagen", type="file")
|
69 |
+
|
70 |
+
def update_image(selected_image_name):
|
71 |
+
image_data = get_selected_image(selected_image_name)
|
72 |
+
return gr.Image.update(value=image_data)
|
73 |
|
74 |
+
image_selector.change(fn=update_image, inputs=image_selector, outputs=image_display)
|
75 |
|
76 |
app = gr.Interface(
|
77 |
+
fn=ImageChat,
|
78 |
+
inputs=image_display,
|
79 |
outputs=gr.Dataframe(headers=["Pregunta", "Respuesta"], label="Resultados"),
|
80 |
title="Análisis de Imagen",
|
81 |
theme="Taithrah/Minimal"
|
82 |
)
|
83 |
|
84 |
+
gr.Interface(
|
85 |
+
fn=lambda: "Selecciona una imagen del carrusel y haz clic en 'Submit' para analizarla.",
|
86 |
+
inputs=[image_selector, image_display],
|
87 |
+
outputs="text"
|
88 |
+
).launch()
|