File size: 1,353 Bytes
9df91a5
7b1849c
388f757
9df91a5
a30b14f
5c6616d
7b1849c
5c6616d
 
7b1849c
388f757
 
 
 
 
 
 
a30b14f
 
 
 
 
388f757
a30b14f
 
9df91a5
a30b14f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3024720
 
a30b14f
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio as gr
import os
import tempfile

# Function to execute the anime upscaler command
def execute_upscaler(input_video, output_path, save_intermediate, async_mode):
    # 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()

    # Save the uploaded video to the temporary directory
    input_video_path = os.path.join(temp_dir, "input_video.mp4")
    input_video.save(input_video_path)

    # 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

# Define the Gradio interface
iface = gr.Interface(
    fn=execute_upscaler,
    inputs=gr.Video(),
    outputs=gr.Video(),
    live=True,
    capture_session=True
)

# Launch the Gradio interface
iface.launch()