| import gradio as gr |
| import os |
| import time |
| |
| print("add sam2") |
| os.system("git clone https://github.com/facebookresearch/sam2.git") |
| time.sleep(3) |
| from sam2segment_structure import generate_trigger_crop |
| |
| dummy_lane_data = { |
| "lanes": [[-2, -2, -2, 814, 751, 688, 625, 562, 500, 438, 373, 305, 234, 160, 88, 16, -64, -2, -2, -2]], |
| "h_samples": [200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390], |
| "raw_file": "driver_182_30frame/06010513_0036.MP4/00270.jpg" |
| } |
|
|
| def process_trigger_with_path(input_image, save_path): |
| |
| os.makedirs(os.path.dirname(save_path), exist_ok=True) |
| |
| |
| input_image.save(save_path) |
|
|
| |
| dummy_lane_data["raw_file"] = save_path |
|
|
| |
| crop_path, mask_path = generate_trigger_crop(save_path, dummy_lane_data) |
| return crop_path, mask_path |
|
|
| demo = gr.Interface( |
| fn=process_trigger_with_path, |
| inputs=[ |
| gr.Image(type="pil", label="Upload Image"), |
| gr.Textbox(label="Path to Save Image (e.g. driver_182_30frame/06010513_0036.MP4/00270.jpg)") |
| ], |
| outputs=[ |
| gr.Image(type="filepath", label="Cropped Image"), |
| gr.Image(type="filepath", label="Cropped Mask") |
| ], |
| title="DBDLD Trigger Demo", |
| description="Upload an image and specify the target save path. The crop and mask will be generated accordingly." |
| ) |
|
|
| demo.launch() |