File size: 1,518 Bytes
c9663b3
a537178
593ffbb
 
462bf87
593ffbb
025cdfe
 
462bf87
593ffbb
 
 
 
 
462bf87
593ffbb
 
d457362
 
 
 
 
 
 
b7ffa5d
c9663b3
a537178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c9663b3
a537178
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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()