mintheinwin commited on
Commit
2e3c260
·
verified ·
1 Parent(s): ed34f8a

add app python file

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ MODEL_REPO_ID = "mintheinwin/3907578Y"
8
+
9
+ def load_model(repo_id):
10
+ download_dir = snapshot_download(repo_id)
11
+ print(download_dir)
12
+ path = os.path.join(download_dir, "best_int8_openvino_model")
13
+ print(path)
14
+ detection_model = YOLO(path, task='detect')
15
+ return detection_model
16
+ detection_model = load_model(MODEL_REPO_ID)
17
+
18
+ # Student ID
19
+ student_info = "Student Id: 3907578Y, Name: Min Thein Win"
20
+
21
+ def predict(pilimg):
22
+ source = pilimg
23
+ result = detection_model.predict(source, conf=0.5, iou=0.5)
24
+ img_bgr = result[0].plot()
25
+ out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
26
+ return out_pilimg
27
+
28
+ gr.Interface(fn=predict,
29
+ inputs=gr.Image(type="pil"),
30
+ outputs=gr.Image(type="pil"),
31
+ title="DETECT TIGER or LION",
32
+ description=student_id,
33
+ ).launch(share=True)