Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -94,25 +94,24 @@ def infer(ref_video_in, ref_image_in):
|
|
94 |
|
95 |
# Execute the inference command
|
96 |
command = ['python', 'inference.py', '--inference_config', file_path]
|
97 |
-
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
98 |
-
# Print logs in real-time
|
99 |
-
while True:
|
100 |
-
output = process.stdout.readline()
|
101 |
-
if output == '' and process.poll() is not None:
|
102 |
-
break
|
103 |
-
if output:
|
104 |
-
print(output.strip())
|
105 |
-
|
106 |
-
# Print any remaining output
|
107 |
-
for output in process.stdout:
|
108 |
-
print(output.strip())
|
109 |
-
for error in process.stderr:
|
110 |
-
print(error.strip())
|
111 |
-
|
112 |
-
# Wait for the process to complete and get the return code
|
113 |
-
return_code = process.wait()
|
114 |
-
print("Inference script finished with return code:", return_code)
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
return "done"
|
118 |
|
|
|
94 |
|
95 |
# Execute the inference command
|
96 |
command = ['python', 'inference.py', '--inference_config', file_path]
|
97 |
+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
# Create threads to handle stdout and stderr
|
100 |
+
stdout_thread = threading.Thread(target=stream_output, args=(process.stdout,))
|
101 |
+
stderr_thread = threading.Thread(target=stream_output, args=(process.stderr,))
|
102 |
+
|
103 |
+
# Start the threads
|
104 |
+
stdout_thread.start()
|
105 |
+
stderr_thread.start()
|
106 |
+
|
107 |
+
# Wait for the process to complete and the threads to finish
|
108 |
+
process.wait()
|
109 |
+
stdout_thread.join()
|
110 |
+
stderr_thread.join()
|
111 |
+
|
112 |
+
print("Inference script finished with return code:", process.returncode)
|
113 |
+
# Print the directory contents
|
114 |
+
print_directory_contents('./outputs')
|
115 |
|
116 |
return "done"
|
117 |
|