averile commited on
Commit
5bf84ff
·
1 Parent(s): 0be7c21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py CHANGED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import yolov5
3
+ import os
4
+ from transformers import pipeline
5
+
6
+ ImageClassifier = pipeline(task="image-classification", model="")
7
+
8
+ model = yolov5.load('./gentle-meadow.pt', device='cpu')
9
+
10
+ def predict(image):
11
+ inp = transforms.ToTensor()(inp).unsqueeze(0)
12
+ with torch.no_grad():
13
+ prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
14
+ confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
15
+ return confidences
16
+
17
+ demo = gr.Interface(fn=predict,
18
+ inputs=gr.inputs.Image(type="pil"),
19
+ outputs=gr.outputs.Label(num_top_classes=3),
20
+ examples=[["cheetah.jpg"]],
21
+ )
22
+
23
+ demo.launch()