| import gradio as gr | |
| from controller import Controller | |
| import time | |
| import os | |
| def process_command(command): | |
| """处理用户输入的命令""" | |
| controller = Controller() | |
| success, message = controller.execute_command(command) | |
| return message | |
| # 创建 Gradio 界面 | |
| def create_interface(): | |
| with gr.Blocks(title="Mac Vision Control Agent") as interface: | |
| gr.Markdown(""" | |
| # Mac Vision Control Agent | |
| 使用自然语言控制您的 Mac。输入您想要执行的操作,系统将自动分析屏幕并执行相应操作。 | |
| 示例命令: | |
| - "打开 Safari 并访问 google.com" | |
| - "在 Finder 中打开下载文件夹" | |
| - "打开系统偏好设置中的显示器选项" | |
| """) | |
| with gr.Row(): | |
| command_input = gr.Textbox( | |
| label="输入命令", | |
| placeholder="请输入自然语言命令...", | |
| lines=2 | |
| ) | |
| with gr.Row(): | |
| submit_btn = gr.Button("执行") | |
| output = gr.Textbox(label="执行结果") | |
| submit_btn.click( | |
| fn=process_command, | |
| inputs=command_input, | |
| outputs=output | |
| ) | |
| return interface | |
| if __name__ == "__main__": | |
| interface = create_interface() | |
| interface.queue() # 添加队列支持 | |
| interface.launch( | |
| server_name="0.0.0.0", # 改回 0.0.0.0 | |
| server_port=7861, | |
| share=True, | |
| auth=None, | |
| inbrowser=True, | |
| show_error=True, # 显示详细错误信息 | |
| quiet=False # 显示更多日志 | |
| ) |