Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#import gradio as gr
|
2 |
+
#from ultralytics import YOLO
|
3 |
+
|
4 |
+
#def greet(name):
|
5 |
+
# return "Hello " + name + "!!"
|
6 |
+
|
7 |
+
#demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
8 |
+
#demo.launch()
|
9 |
+
|
10 |
+
from ultralytics import YOLO
|
11 |
+
from PIL import Image
|
12 |
+
import gradio as gr
|
13 |
+
from huggingface_hub import snapshot_download
|
14 |
+
import os
|
15 |
+
|
16 |
+
model_path = "best_int8_openvino_model"
|
17 |
+
|
18 |
+
def load_model(repo_id):
|
19 |
+
download_dir = snapshot_download(repo_id)
|
20 |
+
print(download_dir)
|
21 |
+
path = os.path.join(download_dir, "best_int8_openvino_model")
|
22 |
+
print(path)
|
23 |
+
detection_model = YOLO(path, task='detect')
|
24 |
+
|
25 |
+
return detection_model
|
26 |
+
|
27 |
+
|
28 |
+
def predict(pilimg):
|
29 |
+
|
30 |
+
source = pilimg
|
31 |
+
# x = np.asarray(pilimg)
|
32 |
+
# print(x.shape)
|
33 |
+
result = detection_model.predict(source, conf=0.5, iou=0.6)
|
34 |
+
img_bgr = result[0].plot()
|
35 |
+
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
|
36 |
+
|
37 |
+
return out_pilimg
|
38 |
+
|
39 |
+
|
40 |
+
#REPO_ID = "Jason-NYP/6304871K"
|
41 |
+
REPO_ID = "ITI107-2024S2/6304871K"
|
42 |
+
detection_model = load_model(REPO_ID)
|
43 |
+
|
44 |
+
gr.Interface(fn=predict,
|
45 |
+
inputs=gr.Image(type="pil"),
|
46 |
+
outputs=gr.Image(type="pil")
|
47 |
+
).launch(share=True)
|