Spaces:
Runtime error
Runtime error
1lint
commited on
Commit
·
aff7142
1
Parent(s):
5d1198f
add original video display
Browse files
app.py
CHANGED
|
@@ -66,19 +66,32 @@ def download_yt_url(url: str, filename: str = "%(title)s", format = 'mp4'):
|
|
| 66 |
|
| 67 |
return output_path
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
# ideally yt_url should be validated
|
| 73 |
def acapellify_url(yt_url, gr_request: gr.Request):
|
| 74 |
|
| 75 |
# example filename: https://www.youtube.com/watch?v=TasKo5HHWb4 -> TasKo5HHWb4
|
| 76 |
-
filename = yt_url.
|
| 77 |
|
| 78 |
video_path = download_yt_url(yt_url, filename)
|
| 79 |
|
| 80 |
new_video_path, new_audio_path = process_video(video_path)
|
| 81 |
-
return new_video_path, new_audio_path, wrap_html(
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
|
| 84 |
def load_mystery_video(gr_request: gr.Request):
|
|
@@ -87,14 +100,14 @@ def load_mystery_video(gr_request: gr.Request):
|
|
| 87 |
|
| 88 |
selected_video = video_paths[random.randrange(len(video_paths))]
|
| 89 |
|
| 90 |
-
|
| 91 |
-
selected_audio = Path(VIDEO_DIRECTORY) / f"{
|
| 92 |
-
|
| 93 |
|
| 94 |
selected_video = str(selected_video)
|
| 95 |
selected_audio = str(selected_audio)
|
| 96 |
|
| 97 |
-
return selected_video, selected_audio, wrap_html(
|
| 98 |
|
| 99 |
|
| 100 |
with open("header.md", "r") as markdown_file:
|
|
@@ -104,7 +117,7 @@ with gr.Blocks(theme=theme) as demo:
|
|
| 104 |
|
| 105 |
with gr.Row():
|
| 106 |
header = gr.Markdown(markdown_text)
|
| 107 |
-
with gr.Row().style():
|
| 108 |
|
| 109 |
with gr.Column(scale=0.4, variant="panel"):
|
| 110 |
input_url = gr.Textbox(label="Youtube URL")
|
|
|
|
| 66 |
|
| 67 |
return output_path
|
| 68 |
|
| 69 |
+
|
| 70 |
+
def wrap_html(filename):
|
| 71 |
+
|
| 72 |
+
yt_url = f"https://www.youtube.com/watch?v={filename}"
|
| 73 |
+
|
| 74 |
+
return f"""<h1><center>Original Video</center></h1>
|
| 75 |
+
<center><a href='{yt_url}'>{yt_url}</a></center>
|
| 76 |
+
<br>
|
| 77 |
+
<center><iframe width="560" height="315" src="https://www.youtube.com/embed/{filename}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></center>
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
|
| 81 |
|
| 82 |
# ideally yt_url should be validated
|
| 83 |
def acapellify_url(yt_url, gr_request: gr.Request):
|
| 84 |
|
| 85 |
# example filename: https://www.youtube.com/watch?v=TasKo5HHWb4 -> TasKo5HHWb4
|
| 86 |
+
filename = yt_url.split("=", 1)[-1].split("=", 1)[0]
|
| 87 |
|
| 88 |
video_path = download_yt_url(yt_url, filename)
|
| 89 |
|
| 90 |
new_video_path, new_audio_path = process_video(video_path)
|
| 91 |
+
return new_video_path, new_audio_path, wrap_html(filename)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
|
| 95 |
|
| 96 |
|
| 97 |
def load_mystery_video(gr_request: gr.Request):
|
|
|
|
| 100 |
|
| 101 |
selected_video = video_paths[random.randrange(len(video_paths))]
|
| 102 |
|
| 103 |
+
filename = selected_video.name.replace("acap_", "").split(".", 1)[0]
|
| 104 |
+
selected_audio = Path(VIDEO_DIRECTORY) / f"{filename}.m4a"
|
| 105 |
+
|
| 106 |
|
| 107 |
selected_video = str(selected_video)
|
| 108 |
selected_audio = str(selected_audio)
|
| 109 |
|
| 110 |
+
return selected_video, selected_audio, wrap_html(filename)
|
| 111 |
|
| 112 |
|
| 113 |
with open("header.md", "r") as markdown_file:
|
|
|
|
| 117 |
|
| 118 |
with gr.Row():
|
| 119 |
header = gr.Markdown(markdown_text)
|
| 120 |
+
with gr.Row().style(equal_height=True):
|
| 121 |
|
| 122 |
with gr.Column(scale=0.4, variant="panel"):
|
| 123 |
input_url = gr.Textbox(label="Youtube URL")
|