File size: 862 Bytes
4cf0f83
 
 
765aef1
beb437b
 
 
 
 
 
4cf0f83
 
 
 
 
beb437b
 
4cf0f83
 
 
 
 
 
 
765aef1
 
4cf0f83
 
 
 
 
 
beb437b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()