JJJHHHH commited on
Commit
c093927
·
verified ·
1 Parent(s): 3ad4661

Uploaded app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, "CCR_EthicalSplit_Finetune.pth")
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 = "JJJHHHH/CCR_EthicalSplit_Finetune"
27
+ detection_model = load_model(REPO_ID)
28
+
29
+ gr.Interface(fn=predict,
30
+ inputs=gr.Image(type="pil"),
31
+ outputs=gr.Image(type="pil")
32
+ ).launch(share=True)