Spaces:
No application file
No application file
CR
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
#public model path location
|
8 |
+
MODEL_REPO_ID = "aunghlaing/6319250G"
|
9 |
+
|
10 |
+
#Organizations model path location
|
11 |
+
#MODEL_REPO_ID = "ITI107-2024S2/6319250G"
|
12 |
+
|
13 |
+
#load model
|
14 |
+
def load_model(repo_id):
|
15 |
+
download_dir = snapshot_download(repo_id)
|
16 |
+
print(download_dir)
|
17 |
+
path = os.path.join(download_dir, "best_int8_openvino_model")
|
18 |
+
print(path)
|
19 |
+
detection_model = YOLO(path, task='detect')
|
20 |
+
return detection_model
|
21 |
+
|
22 |
+
detection_model = load_model(MODEL_REPO_ID)
|
23 |
+
|
24 |
+
#Student ID
|
25 |
+
student_info = "Student Id: 6319250G, Name: AHT"
|
26 |
+
|
27 |
+
#prdeict
|
28 |
+
def predict(pilimg):
|
29 |
+
source = pilimg
|
30 |
+
result = detection_model.predict(source, conf=0.5, iou=0.5)
|
31 |
+
img_bgr = result[0].plot()
|
32 |
+
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
|
33 |
+
return out_pilimg
|
34 |
+
|
35 |
+
#UI interface
|
36 |
+
gr.Markdown("# Mask & Shark Detection (Mask/Shark)")
|
37 |
+
gr.Markdown(student_info)
|
38 |
+
gr.Interface(fn=predict,
|
39 |
+
inputs=gr.Image(type="pil",label="Input"),
|
40 |
+
outputs=gr.Image(type="pil",label="Output"),
|
41 |
+
title="Mask & Shark Detection (Mask/Shark)",
|
42 |
+
description=student_info,
|
43 |
+
).launch(share=True)
|