Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from PIL import Image | |
| # Dictionary mapping animals to image file names in the root directory | |
| animal_images = { | |
| "cat": "cat.jpg", | |
| "dog": "dog.jpg", | |
| "bird": "bird.jpg", | |
| "horse": "horse.jpg", | |
| } | |
| def fetch_animal_image(animal): | |
| # Fetch image file name based on user input | |
| image_file = animal_images.get(animal.lower(), "default.jpg") # Fallback image | |
| # Open and return the image from the root directory | |
| img_path = image_file | |
| img = Image.open(img_path) | |
| return img | |
| # Define the Gradio Interface | |
| demo = gr.Interface( | |
| fn=fetch_animal_image, | |
| inputs=gr.Textbox(label="What's your favorite animal?"), | |
| outputs=gr.Image(type="pil"), | |
| title="Favorite Animal Image", | |
| description="Enter the name of your favorite animal and see an image of it." | |
| ) | |
| # Launch the interface | |
| demo.launch() | |