Spaces:
Runtime error
Runtime error
Update app.py
Browse files6 unmodified lines78910111268 unmodified lines818283848586878889909192939495969798996 unmodified linesimport uuidimport shutilimport gzip# Importing the model-related functionsfrom stable_audio_tools import get_pretrained_model68 unmodified linesoutput = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).mul(32767).to(torch.int16).cpu()print("Audio normalized and converted.")# Generate a unique filename for the outputunique_filename = f"output_{uuid.uuid4().hex}.wav"print(f"Saving audio to file: {unique_filename}")# Save to filetorchaudio.save(unique_filename, output, sample_rate)print(f"Audio saved: {unique_filename}")compressed_filename = compress_file(unique_filename)return compressed_filename# # Return the path to the generated audio file# return unique_filenameDESCRIPTION = "Welcome to Raptor APIs"6 unmodified lines7891011121368 unmodified lines8283848586878889909192939495969798991001011021031041051061071081096 unmodified linesimport uuidimport shutilimport gzipimport io# Importing the model-related functionsfrom stable_audio_tools import get_pretrained_model68 unmodified linesoutput = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).mul(32767).to(torch.int16).cpu()print("Audio normalized and converted.")# # Generate a unique filename for the output# unique_filename = f"output_{uuid.uuid4().hex}.wav"# print(f"Saving audio to file: {unique_filename}")# # Save to file# torchaudio.save(unique_filename, output, sample_rate)# print(f"Audio saved: {unique_filename}")# compressed_filename = compress_file(unique_filename)# return compressed_filename# # Return the path to the generated audio file# return unique_filename# Convert audio tensor to bytesbyte_io = io.BytesIO()torchaudio.save(byte_io, output, sample_rate, format="wav")byte_io.seek(0)audio_bytes = byte_io.read()print("Audio converted to bytes.")return audio_bytesDESCRIPTION = "Welcome to Raptor APIs"
app.py+18-8