Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
def select_model(model_name):
|
| 5 |
+
return pipeline("image-classification", model=model_name)
|
| 6 |
+
|
| 7 |
+
def predict(image, model_name):
|
| 8 |
+
pipeline = select_model(model_name)
|
| 9 |
+
predicts = pipeline(image)
|
| 10 |
+
return image, {p["label"]: p["score"] for p in predicts}
|
| 11 |
+
|
| 12 |
+
iface = gr.Interface(
|
| 13 |
+
predict,
|
| 14 |
+
inputs=[
|
| 15 |
+
gr.Image(label="Input", sources=["upload", "webcam"], type="pil"),
|
| 16 |
+
gr.Dropdown(label="Model Name", choices=["miittnnss/pet-classifier", "miittnnss/pet-classifier-v2"], value="miittnnss/pet-classifier-v2")
|
| 17 |
+
],
|
| 18 |
+
outputs=[
|
| 19 |
+
gr.Image(label="Processed"),
|
| 20 |
+
gr.Label(label="Result")
|
| 21 |
+
],
|
| 22 |
+
title="Pet Classifier"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
iface.launch(debug=True)
|