Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -20,15 +20,11 @@ def submit_job(audio_file, preset, beat_sensitivity, fps, width, height):
|
|
20 |
# Check file size
|
21 |
file_size_mb = os.path.getsize(audio_file.name) / (1024 * 1024)
|
22 |
if file_size_mb > 3.5:
|
23 |
-
|
24 |
-
logging.error(error_message)
|
25 |
-
return error_message, None
|
26 |
|
27 |
api_key = os.getenv('DEFORUM_API_KEY') # Ensure your environment variable is set
|
28 |
if not api_key:
|
29 |
-
|
30 |
-
logging.error(error_message)
|
31 |
-
return error_message, None
|
32 |
|
33 |
server = "https://deforum.studio"
|
34 |
api_url = f'{server}/api/public/v1/audiovis1'
|
@@ -49,9 +45,7 @@ def submit_job(audio_file, preset, beat_sensitivity, fps, width, height):
|
|
49 |
|
50 |
response = requests.post(api_url, headers=headers, json=payload)
|
51 |
if response.status_code != 201:
|
52 |
-
|
53 |
-
logging.error(error_message)
|
54 |
-
return error_message, None
|
55 |
|
56 |
data = response.json()
|
57 |
tracking_url = f"{server}{data['links']['audiovis1']}"
|
@@ -60,9 +54,7 @@ def submit_job(audio_file, preset, beat_sensitivity, fps, width, height):
|
|
60 |
while True:
|
61 |
response = requests.get(tracking_url, headers=headers)
|
62 |
if response.status_code != 200:
|
63 |
-
|
64 |
-
logging.error(error_message)
|
65 |
-
return error_message, None
|
66 |
|
67 |
tracking_data = response.json()
|
68 |
logging.info(f"Job status: {tracking_data['status']}")
|
@@ -71,13 +63,11 @@ def submit_job(audio_file, preset, beat_sensitivity, fps, width, height):
|
|
71 |
sleep(10)
|
72 |
|
73 |
if tracking_data['status'] != 'succeeded':
|
74 |
-
|
75 |
-
logging.error(error_message)
|
76 |
-
return error_message, None
|
77 |
else:
|
78 |
output_url = tracking_data['links']['outputUrls'][0]
|
79 |
logging.info(f"Job succeeded. Output URL: {output_url}")
|
80 |
-
return output_url
|
81 |
|
82 |
description1 = """
|
83 |
# Audio Visualizer Playground
|
@@ -167,10 +157,8 @@ video, .gr-video {
|
|
167 |
"""
|
168 |
|
169 |
def main(audio_file, preset, beat_sensitivity, fps, width, height):
|
170 |
-
result
|
171 |
-
|
172 |
-
return None, error
|
173 |
-
return result, None
|
174 |
|
175 |
with gr.Blocks(css=custom_css) as demo:
|
176 |
gr.Markdown(description1, elem_id="markdown-text")
|
@@ -191,15 +179,15 @@ with gr.Blocks(css=custom_css) as demo:
|
|
191 |
output_video = gr.Video(label="Output MP4")
|
192 |
output_error = gr.Textbox(label="Error", visible=False)
|
193 |
|
194 |
-
def update_output(video_url
|
195 |
-
if
|
196 |
-
output_error.update(value=
|
197 |
output_video.update(value=None, visible=False)
|
198 |
else:
|
199 |
output_error.update(value="", visible=False)
|
200 |
output_video.update(value=video_url, visible=True)
|
201 |
|
202 |
-
submit_button.click(main, inputs=[audio_file, preset, beat_sensitivity, fps, width, height], outputs=[output_video
|
203 |
|
204 |
if __name__ == "__main__":
|
205 |
demo.launch()
|
|
|
20 |
# Check file size
|
21 |
file_size_mb = os.path.getsize(audio_file.name) / (1024 * 1024)
|
22 |
if file_size_mb > 3.5:
|
23 |
+
raise gr.Error(f"File size is {file_size_mb:.2f}MB, which exceeds the 3.5MB limit. Please use a file that is 3.5MB or smaller.")
|
|
|
|
|
24 |
|
25 |
api_key = os.getenv('DEFORUM_API_KEY') # Ensure your environment variable is set
|
26 |
if not api_key:
|
27 |
+
raise gr.Error("API key is not set in environment variables")
|
|
|
|
|
28 |
|
29 |
server = "https://deforum.studio"
|
30 |
api_url = f'{server}/api/public/v1/audiovis1'
|
|
|
45 |
|
46 |
response = requests.post(api_url, headers=headers, json=payload)
|
47 |
if response.status_code != 201:
|
48 |
+
raise gr.Error(f"Error submitting job: {response.status_code} - {response.text}")
|
|
|
|
|
49 |
|
50 |
data = response.json()
|
51 |
tracking_url = f"{server}{data['links']['audiovis1']}"
|
|
|
54 |
while True:
|
55 |
response = requests.get(tracking_url, headers=headers)
|
56 |
if response.status_code != 200:
|
57 |
+
raise gr.Error(f"Error getting job status: {response.text}")
|
|
|
|
|
58 |
|
59 |
tracking_data = response.json()
|
60 |
logging.info(f"Job status: {tracking_data['status']}")
|
|
|
63 |
sleep(10)
|
64 |
|
65 |
if tracking_data['status'] != 'succeeded':
|
66 |
+
raise gr.Error(f"Job ended with status: {tracking_data['status']}")
|
|
|
|
|
67 |
else:
|
68 |
output_url = tracking_data['links']['outputUrls'][0]
|
69 |
logging.info(f"Job succeeded. Output URL: {output_url}")
|
70 |
+
return output_url
|
71 |
|
72 |
description1 = """
|
73 |
# Audio Visualizer Playground
|
|
|
157 |
"""
|
158 |
|
159 |
def main(audio_file, preset, beat_sensitivity, fps, width, height):
|
160 |
+
result = submit_job(audio_file, preset, beat_sensitivity, fps, width, height)
|
161 |
+
return result
|
|
|
|
|
162 |
|
163 |
with gr.Blocks(css=custom_css) as demo:
|
164 |
gr.Markdown(description1, elem_id="markdown-text")
|
|
|
179 |
output_video = gr.Video(label="Output MP4")
|
180 |
output_error = gr.Textbox(label="Error", visible=False)
|
181 |
|
182 |
+
def update_output(video_url):
|
183 |
+
if isinstance(video_url, str) and video_url.startswith("Error"):
|
184 |
+
output_error.update(value=video_url, visible=True)
|
185 |
output_video.update(value=None, visible=False)
|
186 |
else:
|
187 |
output_error.update(value="", visible=False)
|
188 |
output_video.update(value=video_url, visible=True)
|
189 |
|
190 |
+
submit_button.click(main, inputs=[audio_file, preset, beat_sensitivity, fps, width, height], outputs=[output_video])
|
191 |
|
192 |
if __name__ == "__main__":
|
193 |
demo.launch()
|