miittnnss commited on
Commit
1d612ff
1 Parent(s): 29e65a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -1,24 +1,25 @@
1
  from transformers import pipeline
2
  import gradio as gr
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
 
 
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