Spaces:
Runtime error
Runtime error
zfff
Browse files
app.py
CHANGED
|
@@ -7,22 +7,31 @@ from gradio.outputs import Video
|
|
| 7 |
from video_generator import generate_video, extract_last_frame
|
| 8 |
|
| 9 |
def extract_lyrics(api_response):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
try:
|
| 11 |
words_timing = api_response["results"]["channels"][0]["alternatives"][0]["words"]
|
| 12 |
-
lyrics_chunks = []
|
| 13 |
-
CHUNK_DURATION = 10
|
| 14 |
-
current_chunk = ""
|
| 15 |
-
current_chunk_start_time = 0
|
| 16 |
for word_info in words_timing:
|
| 17 |
word = word_info["word"]
|
| 18 |
start_time = word_info["start"]
|
|
|
|
|
|
|
| 19 |
if start_time >= current_chunk_start_time + CHUNK_DURATION:
|
| 20 |
-
|
| 21 |
current_chunk = ""
|
| 22 |
-
current_chunk_start_time
|
|
|
|
| 23 |
current_chunk += " " + word
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
except KeyError:
|
| 27 |
print("Error in API response:", api_response)
|
| 28 |
return []
|
|
|
|
| 7 |
from video_generator import generate_video, extract_last_frame
|
| 8 |
|
| 9 |
def extract_lyrics(api_response):
|
| 10 |
+
lyrics_with_timing = []
|
| 11 |
+
CHUNK_DURATION = 10
|
| 12 |
+
current_chunk = ""
|
| 13 |
+
current_chunk_start_time = 0
|
| 14 |
+
current_chunk_end_time = 0
|
| 15 |
+
|
| 16 |
try:
|
| 17 |
words_timing = api_response["results"]["channels"][0]["alternatives"][0]["words"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
for word_info in words_timing:
|
| 19 |
word = word_info["word"]
|
| 20 |
start_time = word_info["start"]
|
| 21 |
+
end_time = word_info["end"]
|
| 22 |
+
|
| 23 |
if start_time >= current_chunk_start_time + CHUNK_DURATION:
|
| 24 |
+
lyrics_with_timing.append((current_chunk_start_time, current_chunk_end_time, current_chunk.strip()))
|
| 25 |
current_chunk = ""
|
| 26 |
+
current_chunk_start_time = start_time
|
| 27 |
+
|
| 28 |
current_chunk += " " + word
|
| 29 |
+
current_chunk_end_time = end_time
|
| 30 |
+
|
| 31 |
+
# Adding the last chunk
|
| 32 |
+
lyrics_with_timing.append((current_chunk_start_time, current_chunk_end_time, current_chunk.strip()))
|
| 33 |
+
|
| 34 |
+
return lyrics_with_timing
|
| 35 |
except KeyError:
|
| 36 |
print("Error in API response:", api_response)
|
| 37 |
return []
|