fffiloni commited on
Commit
8d74149
·
verified ·
1 Parent(s): d043cd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -20
app.py CHANGED
@@ -4,14 +4,14 @@ import subprocess
4
  import tempfile
5
  from glob import glob
6
 
7
- def run_inference(image_input, audio_input, progress=gr.Progress(track_tqdm=True)):
8
 
9
  # Create a temporary folder for downloaded and processed images
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",
@@ -19,29 +19,17 @@ def run_inference(image_input, audio_input, progress=gr.Progress(track_tqdm=True
19
  "--input_audio", audio_input,
20
  "--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")
 
4
  import tempfile
5
  from glob import glob
6
 
7
+ def run_inference(image_input, audio_input):
8
 
9
  # Create a temporary folder for downloaded and processed images
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",
 
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
 
32
+
33
  with gr.Blocks() as demo:
34
  with gr.Column():
35
  gr.Markdown("# MEMO")