videoenhancer / app.py
peterkros's picture
Update app.py
afbbb7c verified
import gradio as gr
import os
import tempfile
import shutil
# Function to execute the anime upscaler command
def execute_upscaler(input_video_path, output_path, save_intermediate, async_mode):
if input_video_path is None:
raise ValueError("No video file provided.")
# Determine the path to the model file in the same directory
script_directory = os.path.dirname(os.path.realpath(__file__))
model_path = os.path.join(script_directory, "RealESRGAN_x4plus_anime_6B.pth")
# Create a temporary directory to store the uploaded video
temp_dir = tempfile.mkdtemp()
try:
# Build the command
command = [
"python3",
"anime_upscaler.py",
"-m", model_path,
"-i", input_video_path,
"-o", output_path
]
# Add optional flags
if save_intermediate:
command.append("-s")
if async_mode:
command.append("-a")
# Execute the command
import subprocess
result = subprocess.run(command, capture_output=True, text=True)
# Return the output of the command
return result.stdout
finally:
# Cleanup: Remove the temporary directory
shutil.rmtree(temp_dir)
# Define the Gradio interface
iface = gr.Interface(
fn=execute_upscaler,
inputs=gr.Video(),
outputs=gr.Video(),
live=True
)
# Launch the Gradio interface
iface.launch()