Download twoobjectdetect.py from aunghlaing/objectdetect: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/aunghlaing/objectdetect/resolve/main/twoobjectdetect.py
- Command line
-
hf download hf://aunghlaing/objectdetect/twoobjectdetect.py
-
curl -L -o twoobjectdetect.py https://huggingface.co/aunghlaing/objectdetect/resolve/main/twoobjectdetect.py
1.41 kB
| from ultralytics import YOLO | |
| from PIL import Image | |
| import gradio as gr | |
| from huggingface_hub import snapshot_download | |
| import os | |
| #model_path = "/Users/markk/Downloads/best_int8_openvino_model" | |
| #model_path1 = "C:\Users\aungh\Downloads\6319250G\best_int8_openvino_model" | |
| # Define the path to the YOLOv8 mo | |
| model_path = "best_int8_openvino_model" | |
| #Organizations model path location | |
| MODEL_REPO_ID = "aunghlaing/testmodel" | |
| #load model | |
| def load_model(repo_id): | |
| download_dir = snapshot_download(repo_id) | |
| print(download_dir) | |
| path = os.path.join(download_dir, "best_int8_openvino_model") | |
| print(path) | |
| detection_model = YOLO(path, task='detect') | |
| return detection_model | |
| detection_model = load_model(MODEL_REPO_ID) | |
| #Student ID | |
| student_info = "Student Id: 6319250G, Name: AUNG HTUN" | |
| #prdeict | |
| def predict(pilimg): | |
| source = pilimg | |
| result = detection_model.predict(source, conf=0.5, iou=0.5) | |
| img_bgr = result[0].plot() | |
| out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image | |
| return out_pilimg | |
| #UI interface | |
| gr.Markdown("# Two Object Detection (Shark/Mask)") | |
| gr.Markdown(student_info) | |
| gr.Interface(fn=predict, | |
| inputs=gr.Image(type="pil",label="Input"), | |
| outputs=gr.Image(type="pil",label="Output"), | |
| title="Two Object Detection (Shark/Mask)", | |
| description=student_info, | |
| ).launch(share=True) |