Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -54,11 +54,16 @@ background-size: cover;
|
|
54 |
'''
|
55 |
st.markdown(page_bg_img, unsafe_allow_html=True)
|
56 |
|
57 |
-
def save_to_wordpress(channel1, channel2, sample_rate):
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
# Define your WordPress site URL and authentication credentials
|
64 |
wordpress_url = "https://songlabai.com/xmlrpc.php"
|
@@ -69,8 +74,6 @@ def save_to_wordpress(channel1, channel2, sample_rate):
|
|
69 |
password = "um^VdaNK0H8Vw2*KNJlYABkh"
|
70 |
|
71 |
# Authenticate with WordPress XML-RPC API
|
72 |
-
wav_bytes = BytesIO()
|
73 |
-
sf.write(wav_bytes, stereo_audio, samplerate=sample_rate, format="WAV")
|
74 |
title = f"generated_audio_{datetime.now().timestamp()}.wav"
|
75 |
file_data = {
|
76 |
"name": title,
|
@@ -81,7 +84,6 @@ def save_to_wordpress(channel1, channel2, sample_rate):
|
|
81 |
for _ in range(4):
|
82 |
try:
|
83 |
# Upload the file to WordPress Media Library
|
84 |
-
|
85 |
media_response = wp_client.call(media.UploadFile(file_data))
|
86 |
|
87 |
# Handle the response
|
@@ -151,6 +153,10 @@ def save_to_wordpress(channel1, channel2, sample_rate):
|
|
151 |
break
|
152 |
except Exception as e:
|
153 |
print("Error:", e)
|
|
|
|
|
|
|
|
|
154 |
|
155 |
|
156 |
|
@@ -525,9 +531,15 @@ def load_and_play_generated_audio(response):
|
|
525 |
# Play the audio
|
526 |
st.audio(audio_buffer.getvalue())
|
527 |
|
|
|
|
|
|
|
|
|
|
|
|
|
528 |
with col_btn:
|
529 |
-
st.
|
530 |
-
st.
|
531 |
|
532 |
with col_text:
|
533 |
st.write(
|
|
|
54 |
'''
|
55 |
st.markdown(page_bg_img, unsafe_allow_html=True)
|
56 |
|
|
|
57 |
|
58 |
+
|
59 |
+
def save_to_wordpress(audio_array, sample_rate):
|
60 |
+
# Convert audio_array to float32 if not already
|
61 |
+
audio_array = audio_array.astype(np.float32)
|
62 |
+
|
63 |
+
# Save the audio to a BytesIO buffer
|
64 |
+
wav_bytes = BytesIO()
|
65 |
+
sf.write(wav_bytes, audio_array, samplerate=sample_rate, format='WAV')
|
66 |
+
wav_bytes.seek(0)
|
67 |
|
68 |
# Define your WordPress site URL and authentication credentials
|
69 |
wordpress_url = "https://songlabai.com/xmlrpc.php"
|
|
|
74 |
password = "um^VdaNK0H8Vw2*KNJlYABkh"
|
75 |
|
76 |
# Authenticate with WordPress XML-RPC API
|
|
|
|
|
77 |
title = f"generated_audio_{datetime.now().timestamp()}.wav"
|
78 |
file_data = {
|
79 |
"name": title,
|
|
|
84 |
for _ in range(4):
|
85 |
try:
|
86 |
# Upload the file to WordPress Media Library
|
|
|
87 |
media_response = wp_client.call(media.UploadFile(file_data))
|
88 |
|
89 |
# Handle the response
|
|
|
153 |
break
|
154 |
except Exception as e:
|
155 |
print("Error:", e)
|
156 |
+
continue # Retry on error
|
157 |
+
|
158 |
+
# If upload fails, return placeholders
|
159 |
+
return "https://songlabai.com/contact_us/", "N/A"
|
160 |
|
161 |
|
162 |
|
|
|
531 |
# Play the audio
|
532 |
st.audio(audio_buffer.getvalue())
|
533 |
|
534 |
+
# Save the audio to WordPress and get perm_link and product_code
|
535 |
+
perm_link, product_code = save_to_wordpress(audio_array, sample_rate)
|
536 |
+
|
537 |
+
# Define col_btn and col_text
|
538 |
+
col_btn, col_text = st.columns([2, 4])
|
539 |
+
|
540 |
with col_btn:
|
541 |
+
st.markdown("[Publish your Song](https://songlabai.com/contact_us/)")
|
542 |
+
st.markdown("[Download Song](https://songlabai.com/download-music/)")
|
543 |
|
544 |
with col_text:
|
545 |
st.write(
|