hermanshid commited on
Commit
b913953
·
1 Parent(s): 4131223

first space

Browse files
Files changed (2) hide show
  1. app.py +47 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import yolov5
4
+ from PIL import Image
5
+
6
+ app_title = "License Plate Object Detection"
7
+ models_ids = ['hermanshid/yolo-aksara-jawa']
8
+ article = f"<p style='text-align: center'> <a href='https://huggingface.co/{models_ids[-1]}'>model</a> | <a href='https://huggingface.co/keremberke/license-plate-object-detection'>dataset</a> | <a href='https://github.com/keremberke/awesome-yolov5-models'>awesome-yolov5-models</a> </p>"
9
+
10
+ current_model_id = models_ids[-1]
11
+ model = yolov5.load(current_model_id)
12
+
13
+ examples = [['test_images/hanacaraka.jpg', 0.25, 'hermanshid/yolo-aksara-jawa']]
14
+
15
+
16
+ def predict(image, threshold=0.25, model_id=None):
17
+ # update model if required
18
+ global current_model_id
19
+ global model
20
+ if model_id != current_model_id:
21
+ model = yolov5.load(model_id)
22
+ current_model_id = model_id
23
+
24
+ input_size = 640
25
+
26
+ # perform inference
27
+ model.conf = threshold
28
+ results = model(image, size=input_size)
29
+ numpy_image = results.render()[0]
30
+ output_image = Image.fromarray(numpy_image)
31
+ return output_image
32
+
33
+
34
+ gr.Interface(
35
+ title=app_title,
36
+ description="Created by 'keremberke'",
37
+ article=article,
38
+ fn=predict,
39
+ inputs=[
40
+ gr.Image(type="pil"),
41
+ gr.Slider(maximum=1, step=0.01, value=0.25),
42
+ gr.Dropdown(models_ids, value=models_ids[-1]),
43
+ ],
44
+ outputs=gr.Image(type="pil"),
45
+ examples=examples,
46
+ cache_examples=True if examples else False,
47
+ ).launch(enable_queue=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ yolov5==7.0.5
2
+ gradio==3.15.0
3
+ torch
4
+ huggingface-hub