Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import subprocess
|
| 4 |
+
import datetime
|
| 5 |
+
import sys
|
| 6 |
+
|
| 7 |
+
def run_command(command):
|
| 8 |
+
"""Run a shell command and print its output."""
|
| 9 |
+
print(f"Running command: {' '.join(command)}")
|
| 10 |
+
try:
|
| 11 |
+
subprocess.check_call(command, shell=True)
|
| 12 |
+
except subprocess.CalledProcessError as e:
|
| 13 |
+
print(f"Error running command {command}: {e}")
|
| 14 |
+
sys.exit(1)
|
| 15 |
+
|
| 16 |
+
def check_for_mp4_in_outputs(given_folder):
|
| 17 |
+
# Define the path to the outputs folder
|
| 18 |
+
outputs_folder = given_folder
|
| 19 |
+
|
| 20 |
+
# Check if the outputs folder exists
|
| 21 |
+
if not os.path.exists(outputs_folder):
|
| 22 |
+
return None
|
| 23 |
+
|
| 24 |
+
# Check if there is a .mp4 file in the outputs folder
|
| 25 |
+
mp4_files = [f for f in os.listdir(outputs_folder) if f.endswith('.mp4')]
|
| 26 |
+
|
| 27 |
+
# Return the path to the mp4 file if it exists
|
| 28 |
+
if mp4_files:
|
| 29 |
+
return os.path.join(outputs_folder, mp4_files[0])
|
| 30 |
+
else:
|
| 31 |
+
return None
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def infer():
|
| 35 |
+
# Get the current timestamp
|
| 36 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
| 37 |
+
|
| 38 |
+
output_folder_name = f"results_{timestamp}"
|
| 39 |
+
|
| 40 |
+
# Example: Run the inference script (replace with your actual command)
|
| 41 |
+
run_command(f"{sys.executable} inference_keep.py -i=./assets/examples/synthetic_1.mp4 -o={output_folder_name} --has_aligned --save_video -s=1")
|
| 42 |
+
|
| 43 |
+
# Call the function and print the result
|
| 44 |
+
mp4_file_path = check_for_mp4_in_outputs(output_folder_name)
|
| 45 |
+
print(mp4_file_path)
|
| 46 |
+
|
| 47 |
+
print(f"RESULT: {mp4_file_path}")
|
| 48 |
+
|
| 49 |
+
return result
|
| 50 |
+
|
| 51 |
+
with gr.Blocks() as demo:
|
| 52 |
+
with gr.Column():
|
| 53 |
+
gr.Markdown("# KEEP")
|
| 54 |
+
with gr.Row():
|
| 55 |
+
with gr.Column():
|
| 56 |
+
submit_btn = gr.Button("Submit")
|
| 57 |
+
with gr.Column():
|
| 58 |
+
result = gr.Video()
|
| 59 |
+
|
| 60 |
+
submit_btn.click(
|
| 61 |
+
fn = infer,
|
| 62 |
+
inputs = None,
|
| 63 |
+
outputs = [result],
|
| 64 |
+
show_api=False
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
demo.queue().launch(show_error=True, show_api=False)
|