Spaces:
Runtime error
Runtime error
10
Browse files
app.py
CHANGED
@@ -1,4 +1,42 @@
|
|
1 |
-
import gradio as gr
|
2 |
from gradio_client import Client
|
|
|
|
|
3 |
|
|
|
4 |
client = Client("Qwen/Qwen2-72B-Instruct")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from gradio_client import Client
|
2 |
+
import threading
|
3 |
+
import time
|
4 |
|
5 |
+
# 初始化客户端
|
6 |
client = Client("Qwen/Qwen2-72B-Instruct")
|
7 |
+
|
8 |
+
def timer(stop_event):
|
9 |
+
start_time = time.time()
|
10 |
+
while not stop_event.is_set():
|
11 |
+
elapsed_time = time.time() - start_time
|
12 |
+
print(f"已运行时间:{elapsed_time:.2f} 秒")
|
13 |
+
time.sleep(5) # 每隔5秒打印一次
|
14 |
+
|
15 |
+
def main_task(client, stop_event):
|
16 |
+
try:
|
17 |
+
# 执行预测并打印结果
|
18 |
+
result = client.predict(
|
19 |
+
query="test",
|
20 |
+
history=[],
|
21 |
+
system="You are a helpful assistant.",
|
22 |
+
api_name="/model_chat"
|
23 |
+
)
|
24 |
+
print("预测结果:", result)
|
25 |
+
except Exception as e:
|
26 |
+
print(f"预测过程中发生错误:{e}")
|
27 |
+
finally:
|
28 |
+
stop_event.set() # 无论成功或失败,都设置停止事件
|
29 |
+
|
30 |
+
# 创建停止事件
|
31 |
+
stop_event = threading.Event()
|
32 |
+
|
33 |
+
# 创建并启动计时器线程
|
34 |
+
timer_thread = threading.Thread(target=timer, args=(stop_event,))
|
35 |
+
timer_thread.start()
|
36 |
+
|
37 |
+
# 执行主任务
|
38 |
+
main_task(client, stop_event)
|
39 |
+
|
40 |
+
# 等待计时器线程结束
|
41 |
+
timer_thread.join()
|
42 |
+
print("程序运行结束。")
|