Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
85aaa31
1
Parent(s):
6394bbc
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,9 @@ import spaces
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
from pathlib import Path
|
5 |
-
|
6 |
from model import Jamify
|
7 |
-
|
8 |
# Initialize the Jamify model once
|
9 |
print("Initializing Jamify model...")
|
10 |
jamify_model = Jamify()
|
@@ -12,7 +12,27 @@ print("Jamify model ready.")
|
|
12 |
|
13 |
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
@spaces.GPU(duration=100)
|
18 |
def generate_song(reference_audio, lyrics_file, style_prompt, duration):
|
@@ -22,17 +42,30 @@ def generate_song(reference_audio, lyrics_file, style_prompt, duration):
|
|
22 |
|
23 |
# The model expects paths, so we write the prompt to a temp file if needed
|
24 |
# (This part of the model could be improved to accept the string directly)
|
25 |
-
|
|
|
|
|
26 |
output_path = jamify_model.predict(
|
27 |
reference_audio_path=reference_audio,
|
28 |
-
lyrics_json_path=
|
29 |
style_prompt=style_prompt,
|
30 |
duration_sec=duration
|
|
|
31 |
)
|
32 |
|
33 |
return output_path
|
34 |
|
35 |
# Gradio interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
with gr.Blocks() as demo:
|
37 |
gr.Markdown("# Jamify: Music Generation from Lyrics and Style")
|
38 |
gr.Markdown("Provide your lyrics, a style reference (either an audio file or a text prompt), and a desired duration to generate a song.")
|
@@ -40,7 +73,12 @@ with gr.Blocks() as demo:
|
|
40 |
with gr.Row():
|
41 |
with gr.Column():
|
42 |
gr.Markdown("### Inputs")
|
43 |
-
lyrics_file = gr.
|
|
|
|
|
|
|
|
|
|
|
44 |
duration_slider = gr.Slider(minimum=5, maximum=180, value=30, step=1, label="Duration (seconds)")
|
45 |
|
46 |
with gr.Tab("Style from Audio"):
|
@@ -56,20 +94,11 @@ with gr.Blocks() as demo:
|
|
56 |
|
57 |
generate_button.click(
|
58 |
fn=generate_song,
|
59 |
-
inputs=[reference_audio,
|
60 |
outputs=output_audio,
|
61 |
api_name="generate_song"
|
62 |
)
|
|
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
examples=[
|
67 |
-
[None, "gt0.json", "A sad, slow, acoustic country song", 30],
|
68 |
-
],
|
69 |
-
inputs=[reference_audio, lyrics_file, style_prompt, duration_slider],
|
70 |
-
outputs=output_audio,
|
71 |
-
fn=generate_song,
|
72 |
-
cache_examples=True
|
73 |
-
)
|
74 |
-
|
75 |
-
demo.queue().launch()
|
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
from pathlib import Path
|
5 |
+
import ast
|
6 |
from model import Jamify
|
7 |
+
import json
|
8 |
# Initialize the Jamify model once
|
9 |
print("Initializing Jamify model...")
|
10 |
jamify_model = Jamify()
|
|
|
12 |
|
13 |
|
14 |
|
15 |
+
|
16 |
+
def parse(file):
|
17 |
+
parsed_data = []
|
18 |
+
with open(file, 'r') as f:
|
19 |
+
content = f.read()
|
20 |
+
for line in f:
|
21 |
+
line = line.strip()
|
22 |
+
if not line:
|
23 |
+
continue
|
24 |
+
start,end,word = line.split(' ')
|
25 |
+
data_point = {
|
26 |
+
"word": word,
|
27 |
+
"start": float(start),
|
28 |
+
"end": float(end)
|
29 |
+
}
|
30 |
+
parsed_data.append(data_point)
|
31 |
+
|
32 |
+
with open('temp.json','w') as f:
|
33 |
+
json.dump(parsed_data,f)
|
34 |
+
|
35 |
+
return content
|
36 |
|
37 |
@spaces.GPU(duration=100)
|
38 |
def generate_song(reference_audio, lyrics_file, style_prompt, duration):
|
|
|
42 |
|
43 |
# The model expects paths, so we write the prompt to a temp file if needed
|
44 |
# (This part of the model could be improved to accept the string directly)
|
45 |
+
#print(type(lyrics_file))
|
46 |
+
#parse(lyrics_file)
|
47 |
+
#parse(lyrics_file)
|
48 |
output_path = jamify_model.predict(
|
49 |
reference_audio_path=reference_audio,
|
50 |
+
lyrics_json_path='temp.json',
|
51 |
style_prompt=style_prompt,
|
52 |
duration_sec=duration
|
53 |
+
|
54 |
)
|
55 |
|
56 |
return output_path
|
57 |
|
58 |
# Gradio interface
|
59 |
+
def process_text_file(file_obj):
|
60 |
+
"""
|
61 |
+
Reads the content of an uploaded text file.
|
62 |
+
"""
|
63 |
+
if file_obj is not None:
|
64 |
+
with open(file_obj.name, 'r') as f:
|
65 |
+
content = f.read()
|
66 |
+
return content
|
67 |
+
return "No file uploaded."
|
68 |
+
|
69 |
with gr.Blocks() as demo:
|
70 |
gr.Markdown("# Jamify: Music Generation from Lyrics and Style")
|
71 |
gr.Markdown("Provide your lyrics, a style reference (either an audio file or a text prompt), and a desired duration to generate a song.")
|
|
|
73 |
with gr.Row():
|
74 |
with gr.Column():
|
75 |
gr.Markdown("### Inputs")
|
76 |
+
#lyrics_file = gr.JSON(label="Lyrics File (.json)")
|
77 |
+
#file = gr.File(label="Upload JSON File", file_types=[".json"])
|
78 |
+
file_input = gr.File(file_types=["text"], file_count="single", label="Upload your text file here")
|
79 |
+
output_text = gr.Textbox(label="File Content", lines=10)
|
80 |
+
|
81 |
+
file_input.upload(parse, inputs=file_input, outputs=output_text)
|
82 |
duration_slider = gr.Slider(minimum=5, maximum=180, value=30, step=1, label="Duration (seconds)")
|
83 |
|
84 |
with gr.Tab("Style from Audio"):
|
|
|
94 |
|
95 |
generate_button.click(
|
96 |
fn=generate_song,
|
97 |
+
inputs=[reference_audio, output_text, style_prompt, duration_slider],
|
98 |
outputs=output_audio,
|
99 |
api_name="generate_song"
|
100 |
)
|
101 |
+
|
102 |
|
103 |
+
demo.queue().launch()
|
104 |
+
#demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|