diff --git a/webui.py b/webui.py new file mode 100644 index 0000000..1b7058e --- /dev/null +++ b/webui.py @@ -0,0 +1,76 @@ +import gradio as gr +import subprocess +import time + +# 示例回调函数 +def process_image(img_path): + print("处理中...") # 在命令行中显示“处理中” + + try: + # 构造命令行参数 + command = [ + ".\\venv\\python.exe", + ".\\run.py", + "--cfg", + "configs/trt_infer.yaml", + "--realtime", + "--dri_video", + "0", + "--src_image", + img_path + ] + + # 执行命令 + result = subprocess.run(command, capture_output=True, text=True) + + # 检查命令是否执行成功 + if result.returncode != 0: + raise subprocess.CalledProcessError(result.returncode, command, output=result.stdout, stderr=result.stderr) + + print("处理完成!") # 在命令行中显示“处理完成!” + return img_path, result.stdout + + except Exception as e: + print("处理失败,请检查摄像头并重试!") # 在命令行中显示错误消息 + print(f"错误详情: {e}") # 打印错误详情以帮助调试 + return None, "处理失败,请检查摄像头并重试!" + +examples_path = "assets/examples/source" + +# 创建 Gradio 界面 +with gr.Blocks() as demo: + gr.Markdown(""" +