File size: 1,207 Bytes
1466014
01a2c70
7b70bcf
01a2c70
447a6c9
7b70bcf
 
 
0b39bab
7b70bcf
 
 
 
61c44a9
8edc036
61c44a9
 
 
 
 
 
 
f360cba
61c44a9
 
45eeceb
 
d809119
01a2c70
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
import ast
import gradio as gr
from ShazamAPI import Shazam

async def detect(audio):
    mp3_file_content_to_recognize = open(audio, 'rb').read()

    shazam = Shazam(
        mp3_file_content_to_recognize
    )
    recognize_generator = shazam.recognizeSong()
    results = ''
    while True:
        try:
            print(recognize_generator)
            results += str(next(recognize_generator))
            data_tuple = ast.literal_eval(results)
            track_info = data_tuple[1]
            title = track_info['track']['title']
            subtitle = track_info['track']['subtitle']
            background_image = track_info['track']['images']['background']
            url = track_info['track']['url']
            return 'Title: ' + title + '\nArtist: ' + subtitle + '\nURL: ' + url, background_image
        except:
            return 'No results found.', None
title = "Music finder using Shazam"
description = "Find the name and other useful informations of your audio file's Music using this Space!"
iface = gr.Interface(fn=detect, title=title, description=description, inputs=[gr.File(label="Upload Audio or Video")], outputs=[gr.Text(label="Info"), gr.Image(label="Cover")])
iface.launch()