sd-audio-cpu / test_gradio_client.py
Drew
token
4e35e69
raw
history blame
998 Bytes
from gradio_client import Client, file
import requests
import os
HF_TOKEN = os.getenv('HF_TOKEN')
client = Client("dskill/sd-audio", hf_token=HF_TOKEN, download_files=True)
result = client.predict(
prompt="Ambient rainfall",
seconds_total=5,
steps=100,
cfg_scale=7,
api_name="/predict"
)
print(result)
# Split the path into parts
parts = result.split(os.sep)
# Extract the last two sections
last_two_sections = os.sep.join(parts[-2:])
print(last_two_sections)
url_root = 'https://dskill-sd-audio.hf.space/file=/tmp/gradio/'
url = url_root + last_two_sections
# Send a GET request to the URL
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
# Open a file in write-binary mode and write the content of the response to it
with open('output.wav', 'wb') as file:
file.write(response.content)
print('File downloaded successfully!')
else:
print('Failed to download the file. Status code:', response.status_code)