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