Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,8 +12,8 @@ def file_to_base64(filepath):
|
|
12 |
base64_message = base64_encoded_data.decode('utf-8')
|
13 |
return base64_message
|
14 |
|
15 |
-
def submit_job(audio_file, preset, beat_sensitivity, fps):
|
16 |
-
api_key = os.getenv('DEFORUM_API_KEY')
|
17 |
if not api_key:
|
18 |
return "Error: API key is not set in environment variables", None
|
19 |
|
@@ -30,7 +30,9 @@ def submit_job(audio_file, preset, beat_sensitivity, fps):
|
|
30 |
"audioData": audio_base64,
|
31 |
"presetName": preset,
|
32 |
"beatSensitivity": beat_sensitivity,
|
33 |
-
"fps": fps
|
|
|
|
|
34 |
}
|
35 |
|
36 |
response = requests.post(api_url, headers=headers, json=payload)
|
@@ -94,7 +96,7 @@ h1, h2, h3, h4, h5, h6 {
|
|
94 |
|
95 |
label {
|
96 |
font-weight: bold;
|
97 |
-
color: #
|
98 |
text-align: center;
|
99 |
}
|
100 |
|
@@ -142,27 +144,33 @@ video, .gr-video {
|
|
142 |
}
|
143 |
"""
|
144 |
|
145 |
-
def main(audio_file, preset, beat_sensitivity, fps):
|
146 |
-
video_url = submit_job(audio_file, preset, beat_sensitivity, fps)
|
147 |
return video_url
|
148 |
|
149 |
with gr.Blocks(css=custom_css) as demo:
|
150 |
gr.Markdown(description1, elem_id="markdown-text")
|
151 |
gr.Markdown(description2, elem_id="markdown-text")
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
output_video = gr.Video(label="Output MP4")
|
161 |
|
162 |
def update_output(video_url):
|
163 |
output_video.update(value=video_url, visible=True)
|
164 |
|
165 |
-
submit_button.click(main, inputs=[audio_file, preset, beat_sensitivity, fps], outputs=[output_video])
|
166 |
|
167 |
if __name__ == "__main__":
|
168 |
demo.launch()
|
|
|
12 |
base64_message = base64_encoded_data.decode('utf-8')
|
13 |
return base64_message
|
14 |
|
15 |
+
def submit_job(audio_file, preset, beat_sensitivity, fps, width, height):
|
16 |
+
api_key = os.getenv('DEFORUM_API_KEY') # Ensure your environment variable is set
|
17 |
if not api_key:
|
18 |
return "Error: API key is not set in environment variables", None
|
19 |
|
|
|
30 |
"audioData": audio_base64,
|
31 |
"presetName": preset,
|
32 |
"beatSensitivity": beat_sensitivity,
|
33 |
+
"fps": fps,
|
34 |
+
"width": width,
|
35 |
+
"height": height
|
36 |
}
|
37 |
|
38 |
response = requests.post(api_url, headers=headers, json=payload)
|
|
|
96 |
|
97 |
label {
|
98 |
font-weight: bold;
|
99 |
+
color: #000000; /* Change label color to black */
|
100 |
text-align: center;
|
101 |
}
|
102 |
|
|
|
144 |
}
|
145 |
"""
|
146 |
|
147 |
+
def main(audio_file, preset, beat_sensitivity, fps, width, height):
|
148 |
+
video_url = submit_job(audio_file, preset, beat_sensitivity, fps, width, height)
|
149 |
return video_url
|
150 |
|
151 |
with gr.Blocks(css=custom_css) as demo:
|
152 |
gr.Markdown(description1, elem_id="markdown-text")
|
153 |
gr.Markdown(description2, elem_id="markdown-text")
|
154 |
+
with gr.Group():
|
155 |
+
with gr.Column():
|
156 |
+
audio_file = gr.File(label="Upload MP3 File", file_types=['audio'])
|
157 |
+
preset = gr.Dropdown(label="Select Visualization Preset", choices=[
|
158 |
+
"pulsing-circles", "pulsing-hexagons", "pulsing-squares", "pulsing-triangles",
|
159 |
+
"rewbs-01", "rewbs-02", "rotating-shapes"
|
160 |
+
])
|
161 |
+
with gr.Row():
|
162 |
+
beat_sensitivity = gr.Slider(label="Beat Sensitivity", minimum=1, maximum=5, step=0.1, value=3)
|
163 |
+
fps = gr.Slider(label="FPS", minimum=12, maximum=24, step=1, value=24)
|
164 |
+
with gr.Row():
|
165 |
+
width = gr.Slider(label="Width", minimum=512, maximum=1024, step=1, value=512)
|
166 |
+
height = gr.Slider(label="Height", minimum=512, maximum=1024, step=1, value=512)
|
167 |
+
submit_button = gr.Button("Submit")
|
168 |
output_video = gr.Video(label="Output MP4")
|
169 |
|
170 |
def update_output(video_url):
|
171 |
output_video.update(value=video_url, visible=True)
|
172 |
|
173 |
+
submit_button.click(main, inputs=[audio_file, preset, beat_sensitivity, fps, width, height], outputs=[output_video])
|
174 |
|
175 |
if __name__ == "__main__":
|
176 |
demo.launch()
|