Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,13 +2,14 @@ import gradio as gr
|
|
| 2 |
from PIL import Image
|
| 3 |
import time
|
| 4 |
import threading
|
|
|
|
| 5 |
# import get_wsl
|
| 6 |
|
| 7 |
|
| 8 |
# 所有button响应的函数
|
| 9 |
|
| 10 |
# 任务处理函数
|
| 11 |
-
def process_task(txt, inimage, p1, p2, p3, p4, progress=gr.Progress()):
|
| 12 |
# 启动一个 15 秒的命令模拟
|
| 13 |
def execute_command():
|
| 14 |
# 这里用time.sleep(15)来模拟命令执行
|
|
@@ -20,15 +21,8 @@ def process_task(txt, inimage, p1, p2, p3, p4, progress=gr.Progress()):
|
|
| 20 |
command_thread = threading.Thread(target=execute_command)
|
| 21 |
command_thread.start()
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
num_steps = 60 # 15秒内分60步,每步0.25秒
|
| 26 |
-
step_time = total_time / num_steps # 每次更新进度条的时间间隔
|
| 27 |
-
|
| 28 |
-
# 让进度条匀速前进
|
| 29 |
-
for i in range(num_steps):
|
| 30 |
-
progress.update(i / (num_steps - 1)) # 只传递值,不带desc
|
| 31 |
-
time.sleep(step_time) # 等待一段时间,保持进度条匀速前进
|
| 32 |
|
| 33 |
command_thread.join() # 等待命令执行完成
|
| 34 |
return Image.open('img/bg.png'), gr.update(visible=True)
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
import time
|
| 4 |
import threading
|
| 5 |
+
import tqdm
|
| 6 |
# import get_wsl
|
| 7 |
|
| 8 |
|
| 9 |
# 所有button响应的函数
|
| 10 |
|
| 11 |
# 任务处理函数
|
| 12 |
+
def process_task(txt, inimage, p1, p2, p3, p4, progress=gr.Progress(track_tqdm=True)):
|
| 13 |
# 启动一个 15 秒的命令模拟
|
| 14 |
def execute_command():
|
| 15 |
# 这里用time.sleep(15)来模拟命令执行
|
|
|
|
| 21 |
command_thread = threading.Thread(target=execute_command)
|
| 22 |
command_thread.start()
|
| 23 |
|
| 24 |
+
for i in progress.tqdm(range(10)): # 这里填进度条段数
|
| 25 |
+
time.sleep(1) # 这里填多久改变一次
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
command_thread.join() # 等待命令执行完成
|
| 28 |
return Image.open('img/bg.png'), gr.update(visible=True)
|