import time from gradio_client import Client def send_local_gradio_command(): """向本地 Gradio 服务发送消息,执行命令""" try: # 初始化 Gradio 客户端 client = Client("http://127.0.0.1:7860/") while True: # 发送命令请求 print("发送请求...") result = client.predict( input_text="cmd_run ls", # 指定命令 api_name="/api_call" # 根据你的 Gradio 服务端的 API 名称调整 ) print("Gradio API 返回内容:") print(result) # 每隔 60 秒发送一次 time.sleep(60) except Exception as e: print(f"请求失败: {e}") if __name__ == "__main__": send_local_gradio_command()