|
|
import gradio as gr |
|
|
import random |
|
|
|
|
|
|
|
|
def classify_cat(image): |
|
|
|
|
|
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} |
|
|
|
|
|
|
|
|
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!") |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |