Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
# Simulated cat breed classifier function
|
| 5 |
+
def classify_cat(image):
|
| 6 |
+
# In a real application, you'd use a proper ML model here
|
| 7 |
+
cat_breeds = ["Persian", "Siamese", "Maine Coon", "British Shorthair", "Russian Blue"]
|
| 8 |
+
confidence = random.uniform(0.7, 0.99)
|
| 9 |
+
return {breed: random.uniform(0.1, confidence) for breed in cat_breeds}
|
| 10 |
+
|
| 11 |
+
# Simulated cat fact generator
|
| 12 |
+
def generate_cat_fact(breed):
|
| 13 |
+
cat_facts = {
|
| 14 |
+
"Persian": "Persian cats are known for their long, luxurious fur and sweet personalities.",
|
| 15 |
+
"Siamese": "Siamese cats are vocal and intelligent, known for their striking blue eyes.",
|
| 16 |
+
"Maine Coon": "Maine Coons are one of the largest domestic cat breeds and love water!",
|
| 17 |
+
"British Shorthair": "British Shorthairs are calm and easygoing cats with plush coats.",
|
| 18 |
+
"Russian Blue": "Russian Blues are gentle and quiet cats with beautiful silver-blue fur."
|
| 19 |
+
}
|
| 20 |
+
return cat_facts.get(breed, "Please select a cat breed!")
|
| 21 |
+
|
| 22 |
+
# Create the Gradio interface
|
| 23 |
+
with gr.Blocks(title="Cat World Demo") as demo:
|
| 24 |
+
gr.Markdown("# Welcome to Cat World! 🐱")
|
| 25 |
+
|
| 26 |
+
with gr.Tab("Cat Breed Classifier"):
|
| 27 |
+
with gr.Row():
|
| 28 |
+
image_input = gr.Image(label="Upload a cat image")
|
| 29 |
+
output = gr.Label(label="Predicted Breeds")
|
| 30 |
+
classify_btn = gr.Button("Classify Cat")
|
| 31 |
+
classify_btn.click(fn=classify_cat, inputs=image_input, outputs=output)
|
| 32 |
+
|
| 33 |
+
with gr.Tab("Cat Facts"):
|
| 34 |
+
breed_dropdown = gr.Dropdown(
|
| 35 |
+
choices=["Persian", "Siamese", "Maine Coon", "British Shorthair", "Russian Blue"],
|
| 36 |
+
label="Select a cat breed"
|
| 37 |
+
)
|
| 38 |
+
fact_output = gr.Textbox(label="Cat Fact")
|
| 39 |
+
fact_btn = gr.Button("Get Cat Fact")
|
| 40 |
+
fact_btn.click(fn=generate_cat_fact, inputs=breed_dropdown, outputs=fact_output)
|
| 41 |
+
|
| 42 |
+
# Launch the demo
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
demo.launch()
|