Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,37 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from TheDistanceAssessor import run, load_segformer, load_yolo
|
| 3 |
|
| 4 |
def process_image(input_image):
|
| 5 |
-
image_size = [1024,1024]
|
| 6 |
-
target_distances = [650,1000,2000]
|
| 7 |
num_ys = 10
|
| 8 |
|
| 9 |
PATH_model_seg = 'SegFormer_B3_1024_finetuned.pth'
|
| 10 |
PATH_model_det = 'yolov8s.pt'
|
| 11 |
model_seg = load_segformer(PATH_model_seg)
|
| 12 |
model_det = load_yolo(PATH_model_det)
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
return output_image
|
| 15 |
|
| 16 |
# Create the Gradio interface
|
| 17 |
iface = gr.Interface(
|
| 18 |
fn=process_image, # The function to be called
|
| 19 |
-
inputs=gr.Image(type="
|
| 20 |
outputs=gr.Image(type="numpy"), # Output type
|
| 21 |
title="Image Processor", # Title of the interface
|
| 22 |
description="Upload an image and get a processed image as output." # Description of the interface
|
|
@@ -24,4 +39,4 @@ iface = gr.Interface(
|
|
| 24 |
|
| 25 |
# Launch the interface
|
| 26 |
if __name__ == "__main__":
|
| 27 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import numpy as np
|
| 4 |
from TheDistanceAssessor import run, load_segformer, load_yolo
|
| 5 |
|
| 6 |
def process_image(input_image):
|
| 7 |
+
image_size = [1024, 1024]
|
| 8 |
+
target_distances = [650, 1000, 2000]
|
| 9 |
num_ys = 10
|
| 10 |
|
| 11 |
PATH_model_seg = 'SegFormer_B3_1024_finetuned.pth'
|
| 12 |
PATH_model_det = 'yolov8s.pt'
|
| 13 |
model_seg = load_segformer(PATH_model_seg)
|
| 14 |
model_det = load_yolo(PATH_model_det)
|
| 15 |
+
|
| 16 |
+
# Convert the input image to a numpy array if necessary
|
| 17 |
+
if isinstance(input_image, str):
|
| 18 |
+
# If the input is a file path, open the image using PIL
|
| 19 |
+
input_image = Image.open(input_image)
|
| 20 |
+
|
| 21 |
+
if isinstance(input_image, Image.Image):
|
| 22 |
+
# Convert PIL image to numpy array
|
| 23 |
+
input_image = np.array(input_image)
|
| 24 |
+
|
| 25 |
+
if not isinstance(input_image, np.ndarray):
|
| 26 |
+
raise ValueError("Input image is not a valid format (string path, PIL image, or numpy array)")
|
| 27 |
+
|
| 28 |
+
output_image = run(input_image, model_seg, model_det, image_size, target_distances, num_ys=num_ys)
|
| 29 |
return output_image
|
| 30 |
|
| 31 |
# Create the Gradio interface
|
| 32 |
iface = gr.Interface(
|
| 33 |
fn=process_image, # The function to be called
|
| 34 |
+
inputs=gr.Image(type="auto"), # Input type auto-detects the type
|
| 35 |
outputs=gr.Image(type="numpy"), # Output type
|
| 36 |
title="Image Processor", # Title of the interface
|
| 37 |
description="Upload an image and get a processed image as output." # Description of the interface
|
|
|
|
| 39 |
|
| 40 |
# Launch the interface
|
| 41 |
if __name__ == "__main__":
|
| 42 |
+
iface.launch()
|