Spaces:
Running
on
A100
Running
on
A100
Update app.py
Browse files
app.py
CHANGED
@@ -67,9 +67,26 @@ def empty_output_folder(output_dir):
|
|
67 |
|
68 |
# Function to create a temporary file with string content
|
69 |
def create_temp_file(content, suffix=".txt"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
fd, path = tempfile.mkstemp(suffix=suffix)
|
71 |
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
72 |
-
f.write(
|
|
|
73 |
return path
|
74 |
|
75 |
def get_last_mp3_file(output_dir):
|
|
|
67 |
|
68 |
# Function to create a temporary file with string content
|
69 |
def create_temp_file(content, suffix=".txt"):
|
70 |
+
content = content.strip()
|
71 |
+
|
72 |
+
# Case 1: If there's no block marker `[]`, treat it as a single-line input
|
73 |
+
if not re.search(r"\[\w+\]", content):
|
74 |
+
formatted_content = " ".join(content.split()) # Normalize spaces to one space
|
75 |
+
else:
|
76 |
+
# Split content into blocks using headers (e.g., [verse], [chorus])
|
77 |
+
blocks = re.split(r"(?=\[\w+\])", content) # Keeps headers in the split parts
|
78 |
+
|
79 |
+
# Remove excess newlines within each block
|
80 |
+
cleaned_blocks = [block.strip() for block in blocks if block.strip()]
|
81 |
+
|
82 |
+
# Ensure exactly two newlines between blocks
|
83 |
+
formatted_content = "\n\n".join(cleaned_blocks)
|
84 |
+
|
85 |
+
# Write to temp file
|
86 |
fd, path = tempfile.mkstemp(suffix=suffix)
|
87 |
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
88 |
+
f.write(formatted_content)
|
89 |
+
|
90 |
return path
|
91 |
|
92 |
def get_last_mp3_file(output_dir):
|