Spaces:
Running
Running
import numpy as np | |
import gradio as gr | |
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) | |
if result not none: | |
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'] | |
else: | |
artist, title, genre, image_url = None, None, None, None | |
return artist, title, genre, image_url | |
def reverse_audio(audio): | |
sr, data = audio | |
return (sr, np.flipud(data)) | |
input_audio = gr.Audio( | |
sources=["upload", "microphone"], | |
waveform_options=gr.WaveformOptions( | |
waveform_color="#01C6FF", | |
waveform_progress_color="#0066B4", | |
skip_length=2, | |
show_controls=False, | |
), | |
) | |
demo = gr.Interface( | |
fn=main_function, | |
inputs=input_audio, | |
outputs=[ | |
gr.Textbox(label="Artist", show_copy_button=True), | |
gr.Textbox(label="Music", show_copy_button=True), | |
gr.Textbox(label="Genre", show_copy_button=True), | |
gr.Image(label="Cover") | |
] | |
) | |
if __name__ == "__main__": | |
demo.launch() |