Spaces:
Sleeping
Sleeping
Commit
·
dcca473
1
Parent(s):
935485e
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,49 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
import
|
|
|
|
|
4 |
|
5 |
# Images
|
6 |
-
torch.hub.download_url_to_file(
|
7 |
-
|
8 |
-
torch.hub.download_url_to_file(
|
9 |
-
|
10 |
-
torch.hub.download_url_to_file(
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
live=True,
|
49 |
-
theme='huggingface',
|
50 |
-
)
|
51 |
-
demo_app.launch(debug=True, enable_queue=True)
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from PIL import Image
|
4 |
+
import json
|
5 |
+
|
6 |
|
7 |
# Images
|
8 |
+
torch.hub.download_url_to_file(
|
9 |
+
'https://i.imgur.com/4GmZXID.jpg', '1.jpg')
|
10 |
+
torch.hub.download_url_to_file(
|
11 |
+
'https://i.imgur.com/ktIGRvs.jpg', '2.jpg')
|
12 |
+
torch.hub.download_url_to_file(
|
13 |
+
'https://i.imgur.com/fSEsXoE.jpg', '3.jpg')
|
14 |
+
torch.hub.download_url_to_file(
|
15 |
+
'https://i.imgur.com/lsVJRzd.jpg', '4.jpg')
|
16 |
+
torch.hub.download_url_to_file(
|
17 |
+
'https://i.imgur.com/1OFmJd1.jpg', '5.jpg')
|
18 |
+
torch.hub.download_url_to_file(
|
19 |
+
'https://i.imgur.com/GhfAWMJ.jpg', '6.jpg')
|
20 |
+
|
21 |
+
# Model
|
22 |
+
# model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # force_reload=True to update
|
23 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', path='plate.pt', source="local")
|
24 |
+
|
25 |
+
def yolo(im, size=1024):
|
26 |
+
g = (size / max(im.size)) # gain
|
27 |
+
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
|
28 |
+
|
29 |
+
results = model(im) # inference
|
30 |
+
results.render() # updates results.imgs with boxes and labels
|
31 |
+
|
32 |
+
df = results.pandas().xyxy[0].to_json(orient="records")
|
33 |
+
res = json.loads(df)
|
34 |
+
|
35 |
+
return [Image.fromarray(results.imgs[0]), res]
|
36 |
+
|
37 |
+
|
38 |
+
inputs = gr.inputs.Image(type='pil', label="Original Image")
|
39 |
+
outputs = [gr.outputs.Image(type="pil", label="Output Image"),
|
40 |
+
gr.outputs.JSON(label="Output JSON")]
|
41 |
+
|
42 |
+
title = "TW_plate_number"
|
43 |
+
description = "TW_plate_number"
|
44 |
+
# article = "<p style='text-align: center'>TW_plate_number <a href=\"http://codh.rois.ac.jp/char-shape/\">日本古典籍くずし字データセット</a>.</p>"
|
45 |
+
|
46 |
+
examples = [['1.jpg'], ['2.jpg'], ['3.jpg'], ['4.jpg'], ['5.jpg'], ['6.jpg']]
|
47 |
+
gr.Interface(yolo, inputs, outputs, title=title, description=description, examples=examples, theme="huggingface").launch(enable_queue=True) # cache_examples=True,
|
48 |
+
|
49 |
+
|
|
|
|
|
|
|
|