Spaces:
Sleeping
Sleeping
umairahmad89
commited on
Commit
•
7d73127
0
Parent(s):
initial commit
Browse files- .gitignore +2 -0
- README.md +0 -0
- app.py +41 -0
- requirements.txt +3 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
best.pt
|
2 |
+
examples/
|
README.md
ADDED
File without changes
|
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from ultralytics import YOLO
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
model = YOLO("./best.pt")
|
6 |
+
|
7 |
+
|
8 |
+
def process_img(img: gr.Image):
|
9 |
+
result = model.predict(img)
|
10 |
+
for r in result:
|
11 |
+
im_bgr = r.plot()
|
12 |
+
return gr.Image(
|
13 |
+
label="Output Image with labels", value=Image.fromarray(im_bgr[..., ::-1])
|
14 |
+
)
|
15 |
+
|
16 |
+
|
17 |
+
with gr.Blocks() as demo:
|
18 |
+
gr.Markdown(value="Port Classification App")
|
19 |
+
|
20 |
+
with gr.Row():
|
21 |
+
with gr.Column():
|
22 |
+
upload_img = gr.Image(label="Upload Image", type="pil")
|
23 |
+
classify_img_button = gr.Button(value="Process Image")
|
24 |
+
|
25 |
+
with gr.Column():
|
26 |
+
output_img = gr.Image(label="Output Image with labels")
|
27 |
+
with gr.Row():
|
28 |
+
gr.Examples(
|
29 |
+
examples=[
|
30 |
+
"./examples/01.jpg",
|
31 |
+
"./examples/02.jpg",
|
32 |
+
"./examples/03.jpg",
|
33 |
+
"./examples/04.jpg",
|
34 |
+
"./examples/05.jpg",
|
35 |
+
"./examples/06.jpg",
|
36 |
+
],
|
37 |
+
inputs=upload_img
|
38 |
+
)
|
39 |
+
classify_img_button.click(fn=process_img, inputs=upload_img, outputs=output_img)
|
40 |
+
|
41 |
+
demo.launch(server_name="0.0.0.0", server_port=7777)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
ultralytics
|
2 |
+
pillow
|
3 |
+
gradio
|