Spaces:
Running
Running
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import gradio as gr
|
3 |
+
from TheDistanceAssessor import run, load_segformer, load_yolo
|
4 |
+
|
5 |
+
def process_image(input_image):
|
6 |
+
image_size = [1024,1024]
|
7 |
+
target_distances = [650,1000,2000]
|
8 |
+
num_ys = 10
|
9 |
+
|
10 |
+
PATH_model_seg = 'SegFormer_B3_1024_finetuned.pth'
|
11 |
+
PATH_model_det = 'yolov8s.pt'
|
12 |
+
model_seg = load_segformer(PATH_model_seg)
|
13 |
+
model_det = load_yolo(PATH_model_det)
|
14 |
+
|
15 |
+
input_image = cv2.cvtColor(input_image, cv2.COLOR_BGR2RGB)
|
16 |
+
output_image = run(input_image, model_seg, model_det, image_size, target_distances, num_ys = num_ys)
|
17 |
+
return output_image
|
18 |
+
|
19 |
+
# Create the Gradio interface
|
20 |
+
iface = gr.Interface(
|
21 |
+
fn=process_image, # The function to be called
|
22 |
+
inputs=gr.Image(type="pil"), # Input type
|
23 |
+
outputs=gr.Image(type="numpy"), # Output type
|
24 |
+
title="Image Processor", # Title of the interface
|
25 |
+
description="Upload an image and get a processed image as output." # Description of the interface
|
26 |
+
)
|
27 |
+
|
28 |
+
# Launch the interface
|
29 |
+
if __name__ == "__main__":
|
30 |
+
iface.launch()
|