Spaces:
Sleeping
Sleeping
import numpy as np | |
import requests | |
import os | |
from scipy.io.wavfile import write | |
def main_function(audio): | |
os.makedirs("out", exist_ok=True) | |
write('test.wav', audio[0], audio[1]) | |
data = { | |
'api_token': '171afdabea68ffcdbd7f102b8611ac63', | |
'return': 'apple_music,spotify', | |
} | |
files = { | |
'file': open('test.wav', 'rb'), | |
} | |
result = requests.post('https://api.audd.io/', data=data, files=files) | |
artist = result.json()['result']['artist'] | |
title = result.json()['result']['title'] | |
genre = result.json()['result']['apple_music']['genreNames'] | |
image_url = result.json()['result']['spotify']['album']['images'][0]['url'] | |
return artist, title, genre, image_url | |
with gr.Blocks() as demo: | |
with gr.Row(): | |
audio_input = gr.Audio( | |
sources=["upload", "microphone"], | |
waveform_options=gr.WaveformOptions( | |
waveform_color="#01C6FF", | |
waveform_progress_color="#0066B4", | |
skip_length=2, | |
show_controls=False, | |
), | |
) | |
with gr.Row(): | |
artist_output = gr.Textbox(label="Artist", show_copy_button=True) | |
title_output = gr.Textbox(label="Music", show_copy_button=True) | |
genre_output = gr.Textbox(label="Genre", show_copy_button=True) | |
with gr.Row(): | |
image_output = gr.Image(label="Cover") | |
demo.launch(inputs=audio_input, outputs=[artist_output, title_output, genre_output, image_output]) |