Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,16 @@
|
|
| 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
model_path = "best_int8_openvino_model"
|
| 11 |
-
|
| 12 |
-
#Organizations model path location
|
| 13 |
-
MODEL_REPO_ID = "best_int8_openvino_modelaunghlaing/testmodel"
|
| 14 |
-
|
| 15 |
-
#load model
|
| 16 |
-
def load_model(repo_id):
|
| 17 |
-
download_dir = snapshot_download(repo_id)
|
| 18 |
-
print(download_dir)
|
| 19 |
-
path = os.path.join(download_dir, "best_int8_openvino_model")
|
| 20 |
-
print(path)
|
| 21 |
-
detection_model = YOLO(path, task='detect')
|
| 22 |
-
return detection_model
|
| 23 |
-
|
| 24 |
-
detection_model = load_model(MODEL_REPO_ID)
|
| 25 |
-
|
| 26 |
-
#Student ID
|
| 27 |
-
student_info = "Student Id: 6319250G, Name: AUNG HTUN"
|
| 28 |
-
|
| 29 |
-
#prdeict
|
| 30 |
-
def predict(pilimg):
|
| 31 |
-
source = pilimg
|
| 32 |
-
result = detection_model.predict(source, conf=0.5, iou=0.5)
|
| 33 |
-
img_bgr = result[0].plot()
|
| 34 |
-
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
|
| 35 |
-
return out_pilimg
|
| 36 |
-
|
| 37 |
-
#UI interface
|
| 38 |
-
gr.Markdown("# Two Object Detection (Shark/Mask)")
|
| 39 |
-
gr.Markdown(student_info)
|
| 40 |
-
gr.Interface(fn=predict,
|
| 41 |
-
inputs=gr.Image(type="pil",label="Input"),
|
| 42 |
-
outputs=gr.Image(type="pil",label="Output"),
|
| 43 |
-
title="Two Object Detection (Shark/Mask)",
|
| 44 |
-
description=student_info,
|
| 45 |
-
).launch(share=True)
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
def greet(name):
|
| 4 |
+
return f"Hello, {name}!"
|
| 5 |
|
| 6 |
+
with gr.Blocks() as demo:
|
| 7 |
+
with gr.Row():
|
| 8 |
+
gr.Markdown("## Welcome to My Gradio App!")
|
| 9 |
+
with gr.Row():
|
| 10 |
+
name_input = gr.Textbox(label="Enter your name")
|
| 11 |
+
output = gr.Textbox(label="Greeting")
|
| 12 |
+
with gr.Row():
|
| 13 |
+
greet_button = gr.Button("Greet")
|
| 14 |
+
greet_button.click(greet, inputs=name_input, outputs=output)
|
| 15 |
|
| 16 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|