miao-zhen commited on
Commit
07d53a0
·
1 Parent(s): 5f1d07d

first trial

Browse files
Files changed (3) hide show
  1. README.md → 1643512C.md +1 -1
  2. app.py +34 -0
  3. requirements.txt +2 -0
README.md → 1643512C.md RENAMED
@@ -1,5 +1,5 @@
1
  ---
2
- title: 1643512C
3
  emoji: 🔥
4
  colorFrom: purple
5
  colorTo: green
 
1
  ---
2
+ title: detect-shoes-bags
3
  emoji: 🔥
4
  colorFrom: purple
5
  colorTo: green
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_model")
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
+ # x = np.asarray(pilimg)
20
+ # print(x.shape)
21
+ result = detection_model.predict(source, conf=0.5, iou=0.6)
22
+ img_bgr = result[0].plot()
23
+ out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
24
+
25
+ return out_pilimg
26
+
27
+
28
+ REPO_ID = "miao-zhen/nyp-iti107"
29
+ detection_model = load_model(REPO_ID)
30
+
31
+ gr.Interface(fn=predict,
32
+ inputs=gr.Image(type="pil"),
33
+ outputs=gr.Image(type="pil")
34
+ ).launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ultralytics
2
+ huggingface_hub