File size: 1,920 Bytes
4bc1a11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
import gradio as gr
import random

# Simulated cat breed classifier function
def classify_cat(image):
    # In a real application, you'd use a proper ML model here
    cat_breeds = ["Persian", "Siamese", "Maine Coon", "British Shorthair", "Russian Blue"]
    confidence = random.uniform(0.7, 0.99)
    return {breed: random.uniform(0.1, confidence) for breed in cat_breeds}

# Simulated cat fact generator
def generate_cat_fact(breed):
    cat_facts = {
        "Persian": "Persian cats are known for their long, luxurious fur and sweet personalities.",
        "Siamese": "Siamese cats are vocal and intelligent, known for their striking blue eyes.",
        "Maine Coon": "Maine Coons are one of the largest domestic cat breeds and love water!",
        "British Shorthair": "British Shorthairs are calm and easygoing cats with plush coats.",
        "Russian Blue": "Russian Blues are gentle and quiet cats with beautiful silver-blue fur."
    }
    return cat_facts.get(breed, "Please select a cat breed!")

# Create the Gradio interface
with gr.Blocks(title="Cat World Demo") as demo:
    gr.Markdown("# Welcome to Cat World! 🐱")
    
    with gr.Tab("Cat Breed Classifier"):
        with gr.Row():
            image_input = gr.Image(label="Upload a cat image")
            output = gr.Label(label="Predicted Breeds")
        classify_btn = gr.Button("Classify Cat")
        classify_btn.click(fn=classify_cat, inputs=image_input, outputs=output)
    
    with gr.Tab("Cat Facts"):
        breed_dropdown = gr.Dropdown(
            choices=["Persian", "Siamese", "Maine Coon", "British Shorthair", "Russian Blue"],
            label="Select a cat breed"
        )
        fact_output = gr.Textbox(label="Cat Fact")
        fact_btn = gr.Button("Get Cat Fact")
        fact_btn.click(fn=generate_cat_fact, inputs=breed_dropdown, outputs=fact_output)

# Launch the demo
if __name__ == "__main__":
    demo.launch()