Spaces:
Running
Running
mubashiralli
commited on
Commit
•
2164e3e
1
Parent(s):
36bb440
adding code for saving to wordpress
Browse files
app.py
CHANGED
@@ -9,7 +9,44 @@ import librosa
|
|
9 |
import soundfile as sf
|
10 |
from scipy.signal import butter, sosfilt
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Try to get API_URL from environment variables, if not found set to a default value
|
15 |
try:
|
@@ -74,8 +111,10 @@ if st.button("Generate Audio") and genre and energy_level and description and te
|
|
74 |
st.text("Generating audio...")
|
75 |
response = requests.post(API_URL, headers=headers, json=payload)
|
76 |
response = response.json()[0]
|
77 |
-
|
78 |
sample_rate = response['sample_rate']
|
|
|
|
|
79 |
st.audio(st_state.audio, format="audio/wav", sample_rate=sample_rate, start_time=0)
|
80 |
|
81 |
# Post-processing options
|
|
|
9 |
import soundfile as sf
|
10 |
from scipy.signal import butter, sosfilt
|
11 |
|
12 |
+
from wordpress_xmlrpc.compat import xmlrpc_client
|
13 |
+
from xmlrpc.client import ServerProxy
|
14 |
+
from io import BytesIO
|
15 |
+
import soundfile as sf
|
16 |
+
from datetime import datetime
|
17 |
+
|
18 |
+
def save_to_wordpress(audio, sample_rate):
|
19 |
+
# Define your WordPress site URL and authentication credentials
|
20 |
+
wordpress_url = 'https://songlabai.com/xmlrpc.php'
|
21 |
+
username = 'admin_h2ibbgql'
|
22 |
+
password = 'um^VdaNK0H8Vw2*KNJlYABkh'
|
23 |
+
|
24 |
+
# Authenticate with WordPress XML-RPC API
|
25 |
+
proxy = ServerProxy(wordpress_url)
|
26 |
+
wav_bytes = BytesIO()
|
27 |
+
sf.write(wav_bytes, audio, samplerate=sample_rate, format='WAV')
|
28 |
+
|
29 |
+
file_data = {
|
30 |
+
'name': f"generated_audio_{datetime.now().timestamp()}.wav",
|
31 |
+
'type': 'audio/x-wav', # Change the MIME type according to your file type
|
32 |
+
'bits': xmlrpc_client.Binary(wav_bytes.getvalue()),
|
33 |
+
}
|
34 |
+
|
35 |
+
for _ in range(4):
|
36 |
+
try:
|
37 |
+
# Upload the file to WordPress Media Library
|
38 |
+
response_upload = proxy.wp.uploadFile(0, username, password, file_data)
|
39 |
+
|
40 |
+
# Handle the response
|
41 |
+
if response_upload['id']:
|
42 |
+
print(response_upload)
|
43 |
+
attachment_id = response_upload['id']
|
44 |
+
print("File successfully uploaded to WordPress with attachment ID:", attachment_id)
|
45 |
+
else:
|
46 |
+
print("Error uploading file to WordPress.")
|
47 |
+
break
|
48 |
+
except Exception as e:
|
49 |
+
print("Error:", e)
|
50 |
|
51 |
# Try to get API_URL from environment variables, if not found set to a default value
|
52 |
try:
|
|
|
111 |
st.text("Generating audio...")
|
112 |
response = requests.post(API_URL, headers=headers, json=payload)
|
113 |
response = response.json()[0]
|
114 |
+
audio = np.array(response['generated_audio'], dtype=np.float32)
|
115 |
sample_rate = response['sample_rate']
|
116 |
+
st_state.audio = audio
|
117 |
+
save_to_wordpress(audio, sample_rate)
|
118 |
st.audio(st_state.audio, format="audio/wav", sample_rate=sample_rate, start_time=0)
|
119 |
|
120 |
# Post-processing options
|