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

Update simple_app.py

Browse files
Files changed (1) hide show
  1. simple_app.py +18 -10
simple_app.py CHANGED
@@ -9,32 +9,40 @@ snapshot_download(
9
  )
10
 
11
  def infer(prompt):
12
- prompt = "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."
13
-
14
  command = [
15
- "python", "-m", "generate",
16
  "--task", "t2v-1.3B",
17
  "--size", "832*480",
18
  "--ckpt_dir", "./Wan2.1-T2V-1.3B",
19
  "--sample_shift", "8",
20
  "--sample_guide_scale", "6",
21
- "--prompt", f"{prompt}",
22
  "--save_file", "generated_video.mp4"
23
  ]
24
 
25
- result = subprocess.run(command, capture_output=True, text=True)
 
 
 
 
 
 
 
26
 
27
- # Print the standard output and error
28
- print("STDOUT:", result.stdout)
29
- print("STDERR:", result.stderr)
 
30
 
 
31
 
32
- if result.returncode == 0:
33
  print("Command executed successfully.")
34
  return "generated_video.mp4"
35
  else:
36
  print("Error executing command.")
37
- raise gr.Error("Error executing command")
38
 
39
  with gr.Blocks() as demo:
40
  with gr.Column():
 
9
  )
10
 
11
  def infer(prompt):
12
+
 
13
  command = [
14
+ "python", "-u", "-m", "generate", # using -u for unbuffered output and omitting .py extension
15
  "--task", "t2v-1.3B",
16
  "--size", "832*480",
17
  "--ckpt_dir", "./Wan2.1-T2V-1.3B",
18
  "--sample_shift", "8",
19
  "--sample_guide_scale", "6",
20
+ "--prompt", prompt,
21
  "--save_file", "generated_video.mp4"
22
  ]
23
 
24
+ # Start the process with unbuffered output and combine stdout and stderr.
25
+ process = subprocess.Popen(
26
+ command,
27
+ stdout=subprocess.PIPE,
28
+ stderr=subprocess.STDOUT,
29
+ text=True,
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.")
42
  return "generated_video.mp4"
43
  else:
44
  print("Error executing command.")
45
+ raise Exception("Error executing command")
46
 
47
  with gr.Blocks() as demo:
48
  with gr.Column():