Spaces:
Running
Running
Upload 2 files
Browse files- app.py +59 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import random
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Dummy classifier function (replace with real model logic)
|
| 7 |
+
def classify_parrot(image):
|
| 8 |
+
# Dummy label list
|
| 9 |
+
labels = ["Hyacinth Macaw", "Eclectus Parrot", "Cockatiel", "Kakapo", "Budgerigar", "Palm Cockatoo", "Sulphur-crested Cockatoo"]
|
| 10 |
+
prediction = random.choice(labels)
|
| 11 |
+
output_img_path = "output_result.png"
|
| 12 |
+
image.save(output_img_path)
|
| 13 |
+
return output_img_path, f"Predicted Species: {prediction}"
|
| 14 |
+
|
| 15 |
+
# Example images (replace with your actual trial images)
|
| 16 |
+
example_images = [
|
| 17 |
+
"examples/hyacinth.jpg",
|
| 18 |
+
"examples/eclectus.jpg",
|
| 19 |
+
"examples/cockatiel.jpg",
|
| 20 |
+
"examples/kakapo.jpg",
|
| 21 |
+
"examples/macaw.jpg",
|
| 22 |
+
"examples/sulphur.jpg",
|
| 23 |
+
"examples/green_parrot.jpg",
|
| 24 |
+
"examples/palm_cockatoo.jpg",
|
| 25 |
+
"examples/yellow_parrot.jpg",
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
with gr.Blocks(title="Parrot60 Classifier") as demo:
|
| 29 |
+
gr.Markdown("## 🦜 Parrot60 Classifier")
|
| 30 |
+
gr.Markdown("This classifier can classify 60 parrot species with 93% accuracy.")
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
with gr.Column():
|
| 34 |
+
image_input = gr.Image(type="pil", label="Input Image", tool="editor")
|
| 35 |
+
submit_btn = gr.Button("Submit")
|
| 36 |
+
clear_btn = gr.Button("Clear")
|
| 37 |
+
with gr.Column():
|
| 38 |
+
output_image = gr.Image(label="Output", type="filepath")
|
| 39 |
+
output_text = gr.Textbox(label="Prediction", lines=1)
|
| 40 |
+
download_output = gr.File(label="Download Output")
|
| 41 |
+
|
| 42 |
+
with gr.Row():
|
| 43 |
+
gr.Markdown("### 🧪 Examples")
|
| 44 |
+
with gr.Row():
|
| 45 |
+
gr.Examples(
|
| 46 |
+
examples=example_images,
|
| 47 |
+
inputs=image_input,
|
| 48 |
+
label="Click to try an example",
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
def run_pipeline(img):
|
| 52 |
+
result_path, label = classify_parrot(img)
|
| 53 |
+
return result_path, label, result_path
|
| 54 |
+
|
| 55 |
+
submit_btn.click(fn=run_pipeline, inputs=image_input, outputs=[output_image, output_text, download_output])
|
| 56 |
+
clear_btn.click(fn=lambda: (None, "", None), outputs=[image_input, output_text, download_output])
|
| 57 |
+
|
| 58 |
+
# Launch app
|
| 59 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
rembg==2.0.67
|
| 2 |
+
onnxruntime==1.22.1
|
| 3 |
+
Pillow==11.2.1
|