import gradio as gr from rapid_undistorted.inference import InferenceEngine import numpy as np # 初始化模型 engine = InferenceEngine("config.yaml") # 添加示例 example_images = [ "images/demo.jpg", "images/demo1.jpg", "images/demo1.png", "images/demo2.png", "images/demo3.jpg", ] # 定义任务和模型选项 tasks = { "unwrap": ["UVDoc", None], "unshadow": ["GCDnet", None], "unblur": ["OpenCvBilateral", "NAFDPM", None], "binarize": ["UnetCnn", None] } def process_image(img_path, unwrap_model, unshadow_model, binarize_model, unblur_model): task_list = [] if unwrap_model: task_list.append(("unwrap", unwrap_model)) if unshadow_model: task_list.append(("unshadow", unshadow_model)) if binarize_model: task_list.append(("binarize", binarize_model)) if unblur_model: task_list.append(("unblur", unblur_model)) unwrapped_img, elapse = engine(img_path, task_list) print(f"doc unwrap elapse: {elapse}") return unwrapped_img.astype(np.uint8),elapse def main(): # 定义Gradio界面 with gr.Blocks(css=""" .scrollable-container { overflow-x: auto; white-space: nowrap; } .header-links { text-align: center; } .header-links a { display: inline-block; text-align: center; margin-right: 10px; /* 调整间距 */ } """) as demo: gr.HTML( "