fffiloni commited on
Commit
ca753f0
·
verified ·
1 Parent(s): f0f4c78

Update simple_app.py

Browse files
Files changed (1) hide show
  1. simple_app.py +22 -5
simple_app.py CHANGED
@@ -1,5 +1,7 @@
1
  import gradio as gr
 
2
  import subprocess
 
3
  from huggingface_hub import snapshot_download
4
 
5
  #Download model
@@ -8,7 +10,7 @@ snapshot_download(
8
  local_dir = "./Wan2.1-T2V-1.3B"
9
  )
10
 
11
- def infer(prompt):
12
 
13
  command = [
14
  "python", "-u", "-m", "generate", # using -u for unbuffered output and omitting .py extension
@@ -30,12 +32,27 @@ def infer(prompt):
30
  bufsize=1 # line-buffered
31
  )
32
 
33
- # Stream output in real time.
34
- with process.stdout:
35
- for line in iter(process.stdout.readline, ''):
36
- print(line, end="") # line already includes a newline
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  process.wait()
 
 
39
 
40
  if process.returncode == 0:
41
  print("Command executed successfully.")
 
1
  import gradio as gr
2
+ import re
3
  import subprocess
4
+ form tqdm import tqdm
5
  from huggingface_hub import snapshot_download
6
 
7
  #Download model
 
10
  local_dir = "./Wan2.1-T2V-1.3B"
11
  )
12
 
13
+ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
14
 
15
  command = [
16
  "python", "-u", "-m", "generate", # using -u for unbuffered output and omitting .py extension
 
32
  bufsize=1 # line-buffered
33
  )
34
 
35
+ progress_bar = None
36
+ # Regex pattern to capture lines like " 10%|█ | 5/50"
37
+ progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
38
+
39
+ for line in iter(process.stdout.readline, ''):
40
+ # Try to parse progress info from the line
41
+ match = progress_pattern.search(line)
42
+ if match:
43
+ current = int(match.group(2))
44
+ total = int(match.group(3))
45
+ if progress_bar is None:
46
+ progress_bar = tqdm(total=total, desc="Video Generation Progress")
47
+ # Update the progress bar only if progress has advanced
48
+ progress_bar.update(current - progress_bar.n)
49
+ else:
50
+ # Print any other log lines as they are
51
+ print(line, end="")
52
 
53
  process.wait()
54
+ if progress_bar is not None:
55
+ progress_bar.close()
56
 
57
  if process.returncode == 0:
58
  print("Command executed successfully.")