Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,34 +67,17 @@ def empty_output_folder(output_dir):
|
|
| 67 |
print(f"Error deleting file {file_path}: {e}")
|
| 68 |
|
| 69 |
# Function to create a temporary file with string content
|
| 70 |
-
def create_temp_file(content, suffix=".txt"):
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
if not re.search(r"\[\w+\]", content):
|
| 75 |
-
# Normalize single-line input to avoid extra newlines
|
| 76 |
-
formatted_content = " ".join(content.split())
|
| 77 |
-
else:
|
| 78 |
-
# Case 2: If there are block markers, ensure blocks are separated by two newlines
|
| 79 |
-
blocks = re.split(r"(?=\[\w+\])", content) # Keeps headers in the split parts
|
| 80 |
-
cleaned_blocks = [block.strip() for block in blocks if block.strip()]
|
| 81 |
-
formatted_content = "\n\n".join(cleaned_blocks) # Ensure exactly two newlines
|
| 82 |
-
|
| 83 |
-
# Create temp file
|
| 84 |
-
fd, path = tempfile.mkstemp(suffix=suffix)
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
except Exception as e:
|
| 91 |
-
print(f"Error writing file: {e}")
|
| 92 |
-
return None
|
| 93 |
|
| 94 |
-
|
| 95 |
-
os.chmod(path, 0o644) # Read & write permissions for owner, read for others
|
| 96 |
-
|
| 97 |
-
return path
|
| 98 |
|
| 99 |
def get_last_mp3_file(output_dir):
|
| 100 |
# List all files in the output directory
|
|
@@ -118,8 +101,8 @@ def get_last_mp3_file(output_dir):
|
|
| 118 |
|
| 119 |
def infer(genre_txt_content, lyrics_txt_content, num_segments, max_new_tokens):
|
| 120 |
# Create temporary files
|
| 121 |
-
genre_txt_path = create_temp_file(genre_txt_content, "
|
| 122 |
-
lyrics_txt_path = create_temp_file(lyrics_txt_content, "
|
| 123 |
|
| 124 |
print(f"Genre TXT path: {genre_txt_path}")
|
| 125 |
print(f"Lyrics TXT path: {lyrics_txt_path}")
|
|
@@ -249,8 +232,7 @@ with gr.Blocks() as demo:
|
|
| 249 |
In the quiet of the evening, shadows start to fall
|
| 250 |
Whispers of the night wind echo through the hall
|
| 251 |
Lost within the silence, I hear your gentle voice
|
| 252 |
-
Guiding me back homeward, making my heart rejoice
|
| 253 |
-
|
| 254 |
[chorus]
|
| 255 |
Don't let this moment fade, hold me close tonight
|
| 256 |
With you here beside me, everything's alright
|
|
@@ -267,8 +249,7 @@ Got my team beside me, no room for fear
|
|
| 267 |
Walking through the streets, beats inside my head
|
| 268 |
Every step I take, closer to the bread
|
| 269 |
People passing by, they don't understand
|
| 270 |
-
Building up my future with my own two hands
|
| 271 |
-
|
| 272 |
[chorus]
|
| 273 |
This is my life, and I'm aiming for the top
|
| 274 |
Never gonna quit, no, I'm never gonna stop
|
|
|
|
| 67 |
print(f"Error deleting file {file_path}: {e}")
|
| 68 |
|
| 69 |
# Function to create a temporary file with string content
|
| 70 |
+
def create_temp_file(content, prefix, suffix=".txt"):
|
| 71 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, mode="w", prefix=prefix, suffix=suffix)
|
| 72 |
+
temp_file.write(content)
|
| 73 |
+
temp_file.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
# Debug: Print file contents
|
| 76 |
+
print(f"\nContent written to {prefix}{suffix}:")
|
| 77 |
+
print(content)
|
| 78 |
+
print("---")
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
+
return temp_file.name
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
def get_last_mp3_file(output_dir):
|
| 83 |
# List all files in the output directory
|
|
|
|
| 101 |
|
| 102 |
def infer(genre_txt_content, lyrics_txt_content, num_segments, max_new_tokens):
|
| 103 |
# Create temporary files
|
| 104 |
+
genre_txt_path = create_temp_file(genre_txt_content, prefix="genre_")
|
| 105 |
+
lyrics_txt_path = create_temp_file(lyrics_txt_content, prefix="lyrics_")
|
| 106 |
|
| 107 |
print(f"Genre TXT path: {genre_txt_path}")
|
| 108 |
print(f"Lyrics TXT path: {lyrics_txt_path}")
|
|
|
|
| 232 |
In the quiet of the evening, shadows start to fall
|
| 233 |
Whispers of the night wind echo through the hall
|
| 234 |
Lost within the silence, I hear your gentle voice
|
| 235 |
+
Guiding me back homeward, making my heart rejoice\n\n
|
|
|
|
| 236 |
[chorus]
|
| 237 |
Don't let this moment fade, hold me close tonight
|
| 238 |
With you here beside me, everything's alright
|
|
|
|
| 249 |
Walking through the streets, beats inside my head
|
| 250 |
Every step I take, closer to the bread
|
| 251 |
People passing by, they don't understand
|
| 252 |
+
Building up my future with my own two hands\n\n
|
|
|
|
| 253 |
[chorus]
|
| 254 |
This is my life, and I'm aiming for the top
|
| 255 |
Never gonna quit, no, I'm never gonna stop
|