Spaces:
Runtime error
Runtime error
zfff
Browse files
app.py
CHANGED
|
@@ -7,34 +7,23 @@ from gradio.outputs import Video
|
|
| 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 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 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 []
|
| 38 |
|
| 39 |
def send_to_deepgram(audio_file_path):
|
| 40 |
# Update with your Deepgram API endpoint and key
|
|
@@ -76,7 +65,8 @@ def analyze_audio(audio_file_path):
|
|
| 76 |
prompt = generate_video_prompt(previous_mood, current_mood, next_mood, tempo, chroma_mean, spectral_contrast_mean, zero_crossing_rate_mean, mfcc_mean, lyrics_summary)
|
| 77 |
description = f"Chunk starting at {start / sr} seconds:<br>Mood: {current_mood}<br>Video Prompt: {prompt}<br><br>"
|
| 78 |
print(f"Generating video for chunk {i + 1}...")
|
| 79 |
-
|
|
|
|
| 80 |
last_frame = extract_last_frame(video)
|
| 81 |
print(f"Description for chunk {i + 1}: {description}")
|
| 82 |
print(f"Video for chunk {i + 1}: {video}")
|
|
|
|
| 7 |
from video_generator import generate_video, extract_last_frame
|
| 8 |
|
| 9 |
def extract_lyrics(api_response):
|
| 10 |
+
words_timing = api_response["results"]["channels"][0]["alternatives"][0]["words"]
|
| 11 |
lyrics_with_timing = []
|
| 12 |
CHUNK_DURATION = 10
|
| 13 |
current_chunk = ""
|
| 14 |
current_chunk_start_time = 0
|
| 15 |
+
for word_info in words_timing:
|
| 16 |
+
word = word_info["word"]
|
| 17 |
+
start_time = word_info["start"]
|
| 18 |
+
if start_time >= current_chunk_start_time + CHUNK_DURATION:
|
|
|
|
|
|
|
|
|
|
| 19 |
end_time = word_info["end"]
|
| 20 |
+
lyrics_with_timing.append((current_chunk_start_time, end_time, current_chunk.strip()))
|
| 21 |
+
current_chunk = ""
|
| 22 |
+
current_chunk_start_time += CHUNK_DURATION
|
| 23 |
+
current_chunk += " " + word
|
| 24 |
+
lyrics_with_timing.append((current_chunk_start_time, words_timing[-1]["end"], current_chunk.strip()))
|
| 25 |
+
return lyrics_with_timing
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
def send_to_deepgram(audio_file_path):
|
| 29 |
# Update with your Deepgram API endpoint and key
|
|
|
|
| 65 |
prompt = generate_video_prompt(previous_mood, current_mood, next_mood, tempo, chroma_mean, spectral_contrast_mean, zero_crossing_rate_mean, mfcc_mean, lyrics_summary)
|
| 66 |
description = f"Chunk starting at {start / sr} seconds:<br>Mood: {current_mood}<br>Video Prompt: {prompt}<br><br>"
|
| 67 |
print(f"Generating video for chunk {i + 1}...")
|
| 68 |
+
lyrics_with_timing = extract_lyrics(deepgram_response)
|
| 69 |
+
video = generate_video(lyrics_with_timing, last_frame)
|
| 70 |
last_frame = extract_last_frame(video)
|
| 71 |
print(f"Description for chunk {i + 1}: {description}")
|
| 72 |
print(f"Video for chunk {i + 1}: {video}")
|