peterkros commited on
Commit
4a0ca8c
·
verified ·
1 Parent(s): 3024720

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -27
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import os
3
  import tempfile
 
4
 
5
  # Function to execute the anime upscaler command
6
  def execute_upscaler(input_video, output_path, save_intermediate, async_mode):
@@ -11,39 +12,43 @@ def execute_upscaler(input_video, output_path, save_intermediate, async_mode):
11
  # Create a temporary directory to store the uploaded video
12
  temp_dir = tempfile.mkdtemp()
13
 
14
- # Save the uploaded video to the temporary directory
15
- input_video_path = os.path.join(temp_dir, "input_video.mp4")
16
- input_video.save(input_video_path)
17
-
18
- # Build the command
19
- command = [
20
- "python3",
21
- "anime_upscaler.py",
22
- "-m", model_path,
23
- "-i", input_video_path,
24
- "-o", output_path
25
- ]
26
-
27
- # Add optional flags
28
- if save_intermediate:
29
- command.append("-s")
30
- if async_mode:
31
- command.append("-a")
32
-
33
- # Execute the command
34
- import subprocess
35
- result = subprocess.run(command, capture_output=True, text=True)
36
-
37
- # Return the output of the command
38
- return result.stdout
 
 
 
 
 
39
 
40
  # Define the Gradio interface
41
  iface = gr.Interface(
42
  fn=execute_upscaler,
43
  inputs=gr.Video(),
44
  outputs=gr.Video(),
45
- live=True,
46
- capture_session=True
47
  )
48
 
49
  # Launch the Gradio interface
 
1
  import gradio as gr
2
  import os
3
  import tempfile
4
+ import shutil
5
 
6
  # Function to execute the anime upscaler command
7
  def execute_upscaler(input_video, output_path, save_intermediate, async_mode):
 
12
  # Create a temporary directory to store the uploaded video
13
  temp_dir = tempfile.mkdtemp()
14
 
15
+ try:
16
+ # Save the uploaded video to the temporary directory
17
+ input_video_path = os.path.join(temp_dir, "input_video.mp4")
18
+ input_video.save(input_video_path)
19
+
20
+ # Build the command
21
+ command = [
22
+ "python3",
23
+ "anime_upscaler.py",
24
+ "-m", model_path,
25
+ "-i", input_video_path,
26
+ "-o", output_path
27
+ ]
28
+
29
+ # Add optional flags
30
+ if save_intermediate:
31
+ command.append("-s")
32
+ if async_mode:
33
+ command.append("-a")
34
+
35
+ # Execute the command
36
+ import subprocess
37
+ result = subprocess.run(command, capture_output=True, text=True)
38
+
39
+ # Return the output of the command
40
+ return result.stdout
41
+
42
+ finally:
43
+ # Cleanup: Remove the temporary directory
44
+ shutil.rmtree(temp_dir)
45
 
46
  # Define the Gradio interface
47
  iface = gr.Interface(
48
  fn=execute_upscaler,
49
  inputs=gr.Video(),
50
  outputs=gr.Video(),
51
+ live=True
 
52
  )
53
 
54
  # Launch the Gradio interface