fffiloni commited on
Commit
4bdb3a5
·
verified ·
1 Parent(s): 5c21044

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -10,24 +10,38 @@ def run_inference(image_input, audio_input, progress=gr.Progress(track_tqdm=True
10
  temp_dir = tempfile.mkdtemp()
11
 
12
  try:
13
- # Run the inference command
14
- subprocess.run(
15
  [
16
  "python", "inference.py",
17
  "--config", "configs/inference.yaml",
18
- "--input_image", image_input,
19
- "--input_audio", audio_input,
20
- "--output_dir", temp_dir,
21
  ],
22
- check=True
 
 
23
  )
24
 
25
- # Collect the output images
 
 
 
 
 
 
 
 
 
 
26
  output_video = glob(os.path.join(temp_dir, "*.mp4"))
27
- return output_video[0]
28
- except subprocess.CalledProcessError as e:
 
29
  raise gr.Error(f"Error during inference: {str(e)}")
30
 
 
31
  with gr.Blocks() as demo:
32
  with gr.Column():
33
  gr.Markdown("# MEMO")
 
10
  temp_dir = tempfile.mkdtemp()
11
 
12
  try:
13
+ # Start the subprocess with Popen to capture logs
14
+ process = subprocess.Popen(
15
  [
16
  "python", "inference.py",
17
  "--config", "configs/inference.yaml",
18
+ f"--input_image={image_input}",
19
+ f"--input_audio={audio_input}",
20
+ f"--output_dir={temp_dir}",
21
  ],
22
+ stdout=subprocess.PIPE, # Capture standard output
23
+ stderr=subprocess.PIPE, # Capture standard error
24
+ text=True, # Decode output to text (instead of bytes)
25
  )
26
 
27
+ # Stream logs from the subprocess in real-time
28
+ for line in process.stdout:
29
+ print(line, end="") # Print logs to the console (or handle them as needed)
30
+
31
+ # Wait for the subprocess to finish and check for errors
32
+ process.wait()
33
+ if process.returncode != 0:
34
+ error_message = process.stderr.read()
35
+ raise gr.Error(f"Inference failed with error: {error_message}")
36
+
37
+ # Collect the output video
38
  output_video = glob(os.path.join(temp_dir, "*.mp4"))
39
+ return output_video[0] if output_video else "No video generated."
40
+
41
+ except Exception as e:
42
  raise gr.Error(f"Error during inference: {str(e)}")
43
 
44
+
45
  with gr.Blocks() as demo:
46
  with gr.Column():
47
  gr.Markdown("# MEMO")