Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,7 +27,7 @@ def ImageChat(image):
|
|
27 |
if isinstance(image, np.ndarray):
|
28 |
img = PIL.Image.fromarray(image)
|
29 |
else:
|
30 |
-
img = PIL.Image
|
31 |
except Exception as e:
|
32 |
return str(e)
|
33 |
|
@@ -47,7 +47,7 @@ def ImageChat(image):
|
|
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 = {
|
@@ -57,7 +57,7 @@ preloaded_images = {
|
|
57 |
}
|
58 |
|
59 |
def get_selected_image(image_name):
|
60 |
-
return
|
61 |
|
62 |
with gr.Blocks() as app:
|
63 |
image_selector = gr.Radio(
|
@@ -68,7 +68,8 @@ with gr.Blocks() as app:
|
|
68 |
image_display = gr.Image(label="Imagen", type="pil")
|
69 |
|
70 |
def update_image(selected_image_name):
|
71 |
-
|
|
|
72 |
|
73 |
image_selector.change(fn=update_image, inputs=image_selector, outputs=image_display)
|
74 |
|
|
|
27 |
if isinstance(image, np.ndarray):
|
28 |
img = PIL.Image.fromarray(image)
|
29 |
else:
|
30 |
+
img = image # image is already a PIL.Image object
|
31 |
except Exception as e:
|
32 |
return str(e)
|
33 |
|
|
|
47 |
|
48 |
def load_image(image_path):
|
49 |
with open(image_path, "rb") as image_file:
|
50 |
+
return PIL.Image.open(io.BytesIO(image_file.read()))
|
51 |
|
52 |
# Preloaded images
|
53 |
preloaded_images = {
|
|
|
57 |
}
|
58 |
|
59 |
def get_selected_image(image_name):
|
60 |
+
return load_image(preloaded_images[image_name])
|
61 |
|
62 |
with gr.Blocks() as app:
|
63 |
image_selector = gr.Radio(
|
|
|
68 |
image_display = gr.Image(label="Imagen", type="pil")
|
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 |
|