Spaces:
Sleeping
Sleeping
File size: 1,079 Bytes
150837c 94fb728 150837c 8865845 150837c 8865845 94fb728 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import os
import tempfile
import typing
import requests
class AudioGeneration:
def __init__(self):
self.session = requests.session()
def request_generation(self, prompt: typing.Union[str, typing.List[str]]):
response = self.session.post(self.endpoint + "generate", json={
"caption": prompt
})
file_path = response.json().get("file_path")
return file_path
def request_download(self, file_path: str):
response = self.session.post(self.endpoint + "download", json={
"file_path": file_path
})
audio_file_path = None
with tempfile.NamedTemporaryFile(delete=False) as f:
audio_file_path = f.name
f.write(response.content)
return audio_file_path
def generate(self, prompt: typing.Union[str, typing.List[str]], endpoint: str):
self.endpoint = endpoint
stored_file_path = self.request_generation(prompt)
audio_file = self.request_download(stored_file_path)
return audio_file
|