HOPStudio commited on
Commit
ea20bf7
·
verified ·
1 Parent(s): 8f466b4

Create live.py

Browse files
Files changed (1) hide show
  1. live.py +26 -0
live.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ from gradio_client import Client
3
+
4
+ def send_local_gradio_command():
5
+ """向本地 Gradio 服务发送消息,执行命令"""
6
+ try:
7
+ # 初始化 Gradio 客户端
8
+ client = Client("http://127.0.0.1:7860/")
9
+
10
+ while True:
11
+ # 发送命令请求
12
+ print("发送请求...")
13
+ result = client.predict(
14
+ input_text="cmd_run ls", # 指定命令
15
+ api_name="/api_call" # 根据你的 Gradio 服务端的 API 名称调整
16
+ )
17
+ print("Gradio API 返回内容:")
18
+ print(result)
19
+
20
+ # 每隔 60 秒发送一次
21
+ time.sleep(60)
22
+ except Exception as e:
23
+ print(f"请求失败: {e}")
24
+
25
+ if __name__ == "__main__":
26
+ send_local_gradio_command()