Joshua Long Yu Xuan commited on
Commit
911b00a
·
1 Parent(s): 9889416

added files from existing space

Browse files
Files changed (3) hide show
  1. .gitignore +2 -0
  2. app.py +29 -0
  3. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ venv
2
+ .gradio
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ultralytics import YOLO
2
+ from PIL import Image
3
+ import gradio as gr
4
+ from huggingface_hub import snapshot_download
5
+ import os
6
+
7
+ def load_model(repo_id):
8
+ download_dir = snapshot_download(repo_id)
9
+ print(download_dir)
10
+ path = os.path.join(download_dir, "best.pt")
11
+ print(path)
12
+ detection_model = YOLO(path, task='detect')
13
+ return detection_model
14
+
15
+
16
+ def predict(pilimg):
17
+
18
+ source = pilimg
19
+ result = detection_model.predict(source, conf=0.5, iou=0.6)
20
+ img_bgr = result[0].plot()
21
+ out_pilimg = Image.fromarray(img_bgr[..., ::-1])
22
+
23
+ return out_pilimg
24
+
25
+
26
+ REPO_ID = "Joshua-is-tired/paperclip-stickynote"
27
+ detection_model = load_model(REPO_ID)
28
+
29
+ gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs=gr.Image(type="pil")).launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ultralytics
2
+ huggingface_hub