Antoine245 commited on
Commit
329e771
·
1 Parent(s): 88b429a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -6
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import torch
2
  import gradio as gr
3
- import json
4
  from transformers import pipeline
5
 
6
  device = "cuda" if torch.cuda.is_available() else "cpu"
@@ -9,9 +8,7 @@ def predict(image):
9
  classifier = pipeline(task="image-classification")
10
  preds = classifier(image)
11
  preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
12
- prediction_json = json.dumps(preds)
13
- prediction_dict = json.loads(prediction_json)
14
- return prediction_dict
15
 
16
  description = """
17
  """
@@ -21,7 +18,7 @@ gr.Interface(
21
  inputs=[
22
  gr.inputs.Image(label="Image to classify", type="pil"),
23
  ],
24
- outputs="label",
25
- title="Comparateur d'image",
26
  description=description
27
  ).launch()
 
1
  import torch
2
  import gradio as gr
 
3
  from transformers import pipeline
4
 
5
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
8
  classifier = pipeline(task="image-classification")
9
  preds = classifier(image)
10
  preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
11
+ return [pred["label"] for pred in preds] # Return a list of labels only
 
 
12
 
13
  description = """
14
  """
 
18
  inputs=[
19
  gr.inputs.Image(label="Image to classify", type="pil"),
20
  ],
21
+ outputs=gr.outputs.Label(), # Use Label output instead of JSON
22
+ title="Image Classifier",
23
  description=description
24
  ).launch()