Spaces:
Sleeping
Sleeping
Commit
•
8e37fc1
1
Parent(s):
afd30f3
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,10 @@ import time
|
|
3 |
import json
|
4 |
import os
|
5 |
import gradio as gr
|
|
|
|
|
|
|
|
|
6 |
|
7 |
SIMBALS_GLOBAL_DB = 1
|
8 |
SIMBALS_MAIN_DATABASE = 2
|
@@ -10,6 +14,26 @@ SIMBALS_MAIN_DATABASE = 2
|
|
10 |
embed_html1 = '<iframe src="https://open.spotify.com/embed/track/'
|
11 |
embed_html2 = '" width="300" height="380" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>'
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def process(input_path):
|
14 |
# setup the client
|
15 |
client = SimbalsAPIClient(os.environ['TOKEN'], debug=True)
|
@@ -50,12 +74,46 @@ def process(input_path):
|
|
50 |
return "Not found. Please try again."
|
51 |
time.sleep(1)
|
52 |
|
53 |
-
|
54 |
demo = gr.Interface(fn=process,
|
55 |
inputs=gr.Audio(type="filepath"),
|
56 |
outputs=[gr.outputs.Textbox(label="Identification"),"html"]
|
57 |
#examples=example_list,
|
58 |
#cache_examples=False
|
59 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
demo.queue(concurrency_count=2)
|
61 |
demo.launch(debug=True)
|
|
|
3 |
import json
|
4 |
import os
|
5 |
import gradio as gr
|
6 |
+
from pytube import YouTube
|
7 |
+
|
8 |
+
YT_embed_html1 = '<iframe width="560" height="315" src="https://www.youtube.com/embed/'
|
9 |
+
YT_embed_html2 = '" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
|
10 |
|
11 |
SIMBALS_GLOBAL_DB = 1
|
12 |
SIMBALS_MAIN_DATABASE = 2
|
|
|
14 |
embed_html1 = '<iframe src="https://open.spotify.com/embed/track/'
|
15 |
embed_html2 = '" width="300" height="380" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>'
|
16 |
|
17 |
+
|
18 |
+
def download_audio(id_video):
|
19 |
+
video = YouTube(id_video,use_oauth=True, allow_oauth_cache=True)
|
20 |
+
id = id_video.split("?v=")[-1][:11]
|
21 |
+
print("ID youtube ", id)
|
22 |
+
audio_streams = video.streams.filter(only_audio=True)
|
23 |
+
audio_stream = audio_streams[0]
|
24 |
+
audio_file = audio_stream.download()
|
25 |
+
audio_parts = audio_file.split('/')[-1]
|
26 |
+
audio_title = '.'.join(audio_parts.split('.')[:-1])
|
27 |
+
embed_html_all = YT_embed_html1 + id + YT_embed_html2
|
28 |
+
return audio_file, audio_file, embed_html_all
|
29 |
+
|
30 |
+
def process_url(input_path):
|
31 |
+
audio_file, audio_file, embed_html_all = download_audio(input_path)
|
32 |
+
return process(audio_file, embed_html_all)
|
33 |
+
|
34 |
+
def process_file(input_path):
|
35 |
+
return process(input_path, '')
|
36 |
+
|
37 |
def process(input_path):
|
38 |
# setup the client
|
39 |
client = SimbalsAPIClient(os.environ['TOKEN'], debug=True)
|
|
|
74 |
return "Not found. Please try again."
|
75 |
time.sleep(1)
|
76 |
|
77 |
+
'''
|
78 |
demo = gr.Interface(fn=process,
|
79 |
inputs=gr.Audio(type="filepath"),
|
80 |
outputs=[gr.outputs.Textbox(label="Identification"),"html"]
|
81 |
#examples=example_list,
|
82 |
#cache_examples=False
|
83 |
)
|
84 |
+
'''
|
85 |
+
|
86 |
+
with gr.Blocks() as demo:
|
87 |
+
|
88 |
+
with gr.Row():
|
89 |
+
|
90 |
+
with gr.Column():
|
91 |
+
|
92 |
+
with gr.Row():
|
93 |
+
#gr.HTML(embed_html)
|
94 |
+
html = gr.HTML()
|
95 |
+
|
96 |
+
with gr.Row():
|
97 |
+
with gr.Column():
|
98 |
+
audio_url_input = gr.Textbox(placeholder='YouTube video URL', label='YouTube video URL')
|
99 |
+
analyze_url_btn = gr.Button('Search from URL')
|
100 |
+
|
101 |
+
with gr.Row():
|
102 |
+
with gr.Column():
|
103 |
+
audio_input_file = gr.Audio(type="filepath", label='Audio Input')
|
104 |
+
analyze_file_btn = gr.Button('Search from file')
|
105 |
+
|
106 |
+
with gr.Row():
|
107 |
+
with gr.Column():
|
108 |
+
top1 = gr.Audio(label="top1", show_label=True)
|
109 |
+
id = gr.outputs.Textbox(label="Identification", show_label=True)
|
110 |
+
id_html = html = gr.HTML()
|
111 |
+
|
112 |
+
analyze_url_btn.click(process_url, inputs=[audio_url_input],
|
113 |
+
outputs=[id, id_html])
|
114 |
+
|
115 |
+
analyze_file_btn.click(process_file, inputs=[audio_input_file],
|
116 |
+
outputs=[id, id_html])
|
117 |
+
|
118 |
demo.queue(concurrency_count=2)
|
119 |
demo.launch(debug=True)
|