Spaces:
Sleeping
Sleeping
Upload app.py and model weights
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ultralytics import YOLO
|
2 |
+
import gradio as gr
|
3 |
+
from PIL import Image, ImageDraw, ImageFont
|
4 |
+
|
5 |
+
# Load a model
|
6 |
+
model = YOLO("best.pt")
|
7 |
+
|
8 |
+
|
9 |
+
def inference(gr_input):
|
10 |
+
"""
|
11 |
+
Inference function for gradio.
|
12 |
+
"""
|
13 |
+
pred = model(gr_input)
|
14 |
+
draw_prediction = ImageDraw.Draw(gr_input)
|
15 |
+
boxes_predict = pred[0].boxes
|
16 |
+
boxes = boxes_predict.xyxy.tolist()
|
17 |
+
scores = boxes_predict.conf.tolist()
|
18 |
+
for score, box in zip(scores, boxes):
|
19 |
+
x, y, x2, y2 = tuple(box)
|
20 |
+
draw_prediction.rectangle((x, y, x2, y2), outline="red", width=2)
|
21 |
+
return gr_input
|
22 |
+
|
23 |
+
|
24 |
+
def main():
|
25 |
+
imagein = gr.inputs.Image(label="Input Image", type="pil")
|
26 |
+
imageout = gr.outputs.Image(label="Predicted Image", type="pil")
|
27 |
+
|
28 |
+
interface = gr.Interface(
|
29 |
+
fn=inference,
|
30 |
+
inputs=imagein,
|
31 |
+
outputs=imageout,
|
32 |
+
title="Potholes detection",
|
33 |
+
interpretation="default",
|
34 |
+
).launch(debug="True", share="True")
|
35 |
+
|
36 |
+
# launch demo
|
37 |
+
interface.launch()
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
main()
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3885048e6d5a451e3a6b8111b76b907c37cde4c554acbbc9104587a979692f2a
|
3 |
+
size 6228270
|