Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def fetch_animal_image(animal):
|
| 8 |
-
animal_images = {
|
| 9 |
-
"cat": "cat.jpg",
|
| 10 |
-
"dog": "dog.jpg",
|
| 11 |
-
"bird": "bird.jpg",
|
| 12 |
-
"horse": "horse.jpg",
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
# Fetch image file name based on user input
|
| 16 |
image_file = animal_images.get(animal.lower(), "default.jpg") # Fallback image
|
| 17 |
|
| 18 |
-
# Open and return the image
|
| 19 |
-
img_path =
|
| 20 |
img = Image.open(img_path)
|
| 21 |
|
| 22 |
return img
|
|
@@ -32,3 +31,4 @@ demo = gr.Interface(
|
|
| 32 |
|
| 33 |
# Launch the interface
|
| 34 |
demo.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
|
| 4 |
+
# Dictionary mapping animals to image file names in the root directory
|
| 5 |
+
animal_images = {
|
| 6 |
+
"cat": "cat.jpg",
|
| 7 |
+
"dog": "dog.jpg",
|
| 8 |
+
"bird": "bird.jpg",
|
| 9 |
+
"horse": "horse.jpg",
|
| 10 |
+
# Add more animals and image filenames as needed
|
| 11 |
+
}
|
| 12 |
|
| 13 |
def fetch_animal_image(animal):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Fetch image file name based on user input
|
| 15 |
image_file = animal_images.get(animal.lower(), "default.jpg") # Fallback image
|
| 16 |
|
| 17 |
+
# Open and return the image from the root directory
|
| 18 |
+
img_path = image_file
|
| 19 |
img = Image.open(img_path)
|
| 20 |
|
| 21 |
return img
|
|
|
|
| 31 |
|
| 32 |
# Launch the interface
|
| 33 |
demo.launch()
|
| 34 |
+
|