Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,12 @@ import requests
|
|
| 3 |
import base64
|
| 4 |
import json
|
| 5 |
import os
|
|
|
|
| 6 |
from time import sleep
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
def file_to_base64(filepath):
|
| 9 |
with open(filepath, "rb") as file:
|
| 10 |
file_data = file.read()
|
|
@@ -13,9 +17,18 @@ def file_to_base64(filepath):
|
|
| 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 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
server = "https://deforum.studio"
|
| 21 |
api_url = f'{server}/api/public/v1/audiovis1'
|
|
@@ -25,7 +38,6 @@ def submit_job(audio_file, preset, beat_sensitivity, fps, width, height):
|
|
| 25 |
}
|
| 26 |
|
| 27 |
audio_base64 = file_to_base64(audio_file.name)
|
| 28 |
-
|
| 29 |
payload = {
|
| 30 |
"audioData": audio_base64,
|
| 31 |
"presetName": preset,
|
|
@@ -37,32 +49,42 @@ def submit_job(audio_file, preset, beat_sensitivity, fps, width, height):
|
|
| 37 |
|
| 38 |
response = requests.post(api_url, headers=headers, json=payload)
|
| 39 |
if response.status_code != 201:
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
data = response.json()
|
| 43 |
tracking_url = f"{server}{data['links']['audiovis1']}"
|
|
|
|
| 44 |
|
| 45 |
while True:
|
| 46 |
response = requests.get(tracking_url, headers=headers)
|
| 47 |
if response.status_code != 200:
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
|
| 50 |
tracking_data = response.json()
|
|
|
|
| 51 |
if tracking_data['status'] in ['canceled', 'failed', 'succeeded']:
|
| 52 |
break
|
| 53 |
sleep(10)
|
| 54 |
|
| 55 |
if tracking_data['status'] != 'succeeded':
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
else:
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
|
| 60 |
description1 = """
|
| 61 |
# Audio Visualizer Playground
|
| 62 |
-
###
|
| 63 |
"""
|
| 64 |
description2 = """
|
| 65 |
-
#### Please provide feedback for us about which masks you would like to see in our Discord: [discord.gg/deforum](https://discord.gg/deforum)
|
| 66 |
"""
|
| 67 |
|
| 68 |
custom_css = """
|
|
@@ -158,7 +180,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 158 |
"pulsing-circles", "pulsing-hexagons", "pulsing-squares", "pulsing-triangles", "rotating-shapes"
|
| 159 |
])
|
| 160 |
with gr.Row():
|
| 161 |
-
beat_sensitivity = gr.Slider(label="Beat Sensitivity", minimum=1, maximum=5, step=0.1, value=
|
| 162 |
fps = gr.Slider(label="FPS", minimum=12, maximum=24, step=1, value=24)
|
| 163 |
with gr.Row():
|
| 164 |
width = gr.Slider(label="Width", minimum=512, maximum=1024, step=1, value=512)
|
|
|
|
| 3 |
import base64
|
| 4 |
import json
|
| 5 |
import os
|
| 6 |
+
import logging
|
| 7 |
from time import sleep
|
| 8 |
|
| 9 |
+
# Configure logging
|
| 10 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 11 |
+
|
| 12 |
def file_to_base64(filepath):
|
| 13 |
with open(filepath, "rb") as file:
|
| 14 |
file_data = file.read()
|
|
|
|
| 17 |
return base64_message
|
| 18 |
|
| 19 |
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 |
+
error_message = f"Error: File size is {file_size_mb:.2f}MB, which exceeds the 3.5MB limit."
|
| 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 |
+
error_message = "Error: API key is not set in environment variables"
|
| 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'
|
|
|
|
| 38 |
}
|
| 39 |
|
| 40 |
audio_base64 = file_to_base64(audio_file.name)
|
|
|
|
| 41 |
payload = {
|
| 42 |
"audioData": audio_base64,
|
| 43 |
"presetName": preset,
|
|
|
|
| 49 |
|
| 50 |
response = requests.post(api_url, headers=headers, json=payload)
|
| 51 |
if response.status_code != 201:
|
| 52 |
+
error_message = f"Error submitting job: {response.status_code} - {response.text}"
|
| 53 |
+
logging.error(error_message)
|
| 54 |
+
return error_message, None
|
| 55 |
|
| 56 |
data = response.json()
|
| 57 |
tracking_url = f"{server}{data['links']['audiovis1']}"
|
| 58 |
+
logging.info(f"Job submitted successfully. Tracking URL: {tracking_url}")
|
| 59 |
|
| 60 |
while True:
|
| 61 |
response = requests.get(tracking_url, headers=headers)
|
| 62 |
if response.status_code != 200:
|
| 63 |
+
error_message = f"Error getting job status: {response.text}"
|
| 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']}")
|
| 69 |
if tracking_data['status'] in ['canceled', 'failed', 'succeeded']:
|
| 70 |
break
|
| 71 |
sleep(10)
|
| 72 |
|
| 73 |
if tracking_data['status'] != 'succeeded':
|
| 74 |
+
error_message = f"Job ended with status: {tracking_data['status']}"
|
| 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
|
| 84 |
+
### A way for you to easily create audio-synced animation masks for AnimateDiff or Deforum Animations.
|
| 85 |
"""
|
| 86 |
description2 = """
|
| 87 |
+
#### Please provide feedback for us about which masks you like, or would like to see in our animation channel in our Discord: [discord.gg/deforum](https://discord.gg/deforum)
|
| 88 |
"""
|
| 89 |
|
| 90 |
custom_css = """
|
|
|
|
| 180 |
"pulsing-circles", "pulsing-hexagons", "pulsing-squares", "pulsing-triangles", "rotating-shapes"
|
| 181 |
])
|
| 182 |
with gr.Row():
|
| 183 |
+
beat_sensitivity = gr.Slider(label="Beat Sensitivity", minimum=1, maximum=5, step=0.1, value=3)
|
| 184 |
fps = gr.Slider(label="FPS", minimum=12, maximum=24, step=1, value=24)
|
| 185 |
with gr.Row():
|
| 186 |
width = gr.Slider(label="Width", minimum=512, maximum=1024, step=1, value=512)
|