fffiloni commited on
Commit
b71b6bf
1 Parent(s): ea31508

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -0
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import huggingface_hub
3
+ import os
4
+ import subprocess
5
+ import threading
6
+
7
+ # download model
8
+ huggingface_hub.hf_hub_download(
9
+ repo_id='ariesssxu/vta-ldm-clip4clip-v-large',
10
+ local_dir='./ckpt'
11
+ )
12
+
13
+ def stream_output(pipe):
14
+ for line in iter(pipe.readline, ''):
15
+ print(line, end='')
16
+
17
+ def print_directory_contents(path):
18
+ for root, dirs, files in os.walk(path):
19
+ level = root.replace(path, '').count(os.sep)
20
+ indent = ' ' * 4 * (level)
21
+ print(f"{indent}{os.path.basename(root)}/")
22
+ subindent = ' ' * 4 * (level + 1)
23
+ for f in files:
24
+ print(f"{subindent}{f}")
25
+
26
+ def infer(video_in):
27
+
28
+ # Need to find path to gradio temp vid from video input
29
+ # path_to_video
30
+
31
+ print(f"VIDEO IN PATH: {video_in}")
32
+
33
+ # Execute the inference command
34
+ command = ['python', 'inference_from_video.py', '--data_path', video_in]
35
+ process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1)
36
+
37
+ # Create threads to handle stdout and stderr
38
+ stdout_thread = threading.Thread(target=stream_output, args=(process.stdout,))
39
+ stderr_thread = threading.Thread(target=stream_output, args=(process.stderr,))
40
+
41
+ # Start the threads
42
+ stdout_thread.start()
43
+ stderr_thread.start()
44
+
45
+ # Wait for the process to complete and the threads to finish
46
+ process.wait()
47
+ stdout_thread.join()
48
+ stderr_thread.join()
49
+
50
+ print("Inference script finished with return code:", process.returncode)
51
+
52
+ # Need to find where are the results stored, default should be "./outputs/tmp"
53
+ # Print the outputs directory contents
54
+ print_directory_contents('./outputs/tmp')
55
+ return "done"
56
+
57
+ with gr.Blocks() as demo:
58
+ with gr.Column(elem_id="col-container"):
59
+ gr.Markdown("# Video-To-Audio")
60
+ video_in = gr.Video(label='Video IN')
61
+ submit_btn = gr.Button("Submit")
62
+ #output_sound = gr.Audio(label="Audio OUT")
63
+ output_sound = gr.Textbox(label="Audio OUT")
64
+ submit_btn.click(
65
+ fn = infer,
66
+ inputs = [video_in],
67
+ outputs = [output_sound],
68
+ show_api = False
69
+ )
70
+ demo.launch(show_api=False, show_error=True)