8513669W commited on
Commit
3ecfee7
·
verified ·
1 Parent(s): 46c66cd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /content/Assignment/train2/weights/best_int8_openvino_model
2
+
3
+ from ultralytics import YOLO
4
+ from PIL import Image
5
+ import gradio as gr
6
+ from huggingface_hub import snapshot_download
7
+ import os
8
+
9
+ model_path = "/content/Assignment/train2/weights/best_int8_openvino_model"
10
+
11
+ def load_model(repo_id):
12
+ download_dir = snapshot_download(repo_id)
13
+ print(download_dir)
14
+ path = os.path.join(download_dir, "best_int8_openvino_model")
15
+ print(path)
16
+ detection_model = YOLO(path, task='detect')
17
+ return detection_model
18
+
19
+
20
+ def predict(pilimg):
21
+
22
+ source = pilimg
23
+ # x = np.asarray(pilimg)
24
+ # print(x.shape)
25
+ result = detection_model.predict(source, conf=0.5, iou=0.6)
26
+ img_bgr = result[0].plot()
27
+ out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
28
+
29
+ return out_pilimg
30
+
31
+
32
+ REPO_ID = "khengkok/balloon_yolov8"
33
+ detection_model = load_model(REPO_ID)
34
+
35
+ gr.Interface(fn=predict,
36
+ inputs=gr.Image(type="pil"),
37
+ outputs=gr.Image(type="pil")
38
+ ).launch(share=True)