from simbals_apis_public_clients.clients.services import SimbalsAPIClient import time import json import os import gradio as gr SIMBALS_GLOBAL_DB = 1 SIMBALS_MAIN_DATABASE = 2 def process(input_path): # setup the client client = SimbalsAPIClient(os.environ['TOKEN'], debug=True) # init the base parameters with your audio id and an audio url (or a local audio file) ##parameters = client.prepare_request("31415", audio_url="https://simbals:frsavUcaqe99TECR@resources.simbals.com/audio_databases/catalogs/1034/WAV%20Drive%201/BMG%20Production%20Music/101%20Dark%20Orchid%20Music/101DOM032%20The%20Seasons/BMGPM_101DOM032_012_French_Town_by_the_River.wav") #parameters = client.prepare_request("31415", audio_file="BitterEnd.wav") parameters = client.prepare_request("31415", audio_file=input_path) # if you want to use results push mode # parameters = client.prepare_request("your audio id", audio_url="an url to an audio file", results_callback_url="an url on your platform", results_callback_headers = {"a header name": "a header value"}, notify_results_early=False) # add scanmatch service with full_matches option activated, against a chosen and available database #parameters = client.add_scanmatch_full_matches(parameters, SIMBALS_GLOBAL_DB) # add scanmatch service with partial_matches option activated, against a chosen and available database #parameters = client.add_scanmatch_partial_matches(parameters, SIMBALS_GLOBAL_DB) parameters = client.add_scanmatch_partial_fast_matches(parameters, SIMBALS_GLOBAL_DB) # add audio features service with an available database #parameters = client.add_audio_features(parameters, SIMBALS_MAIN_DATABASE) #parameters = client.add_tags(parameters, SIMBALS_MAIN_DATABASE) # launch the request and test for ok/code values ok, code, job_id = client.launch_request(parameters) # try to get the results with obtained job_id. If code is 4, job is not finished. In all other cases, job is finished for i in range(1000): results=client.get_results(job_id) if results[0] != 4: print(json.dumps(results[1], indent=1)) #return json.dumps(results[1], indent=1) output = json.dumps(results[1], indent=1) try : trackname = results[1]["response"]["scanmatch"]['1']['partial_fast_matches'][0]['track']['title'] artistname = results[1]["response"]["scanmatch"]['1']['partial_fast_matches'][0]['artists'][0]['name'] return trackname+" by "+artistname except IndexError: return "Not found. Please try again." time.sleep(1) demo = gr.Interface(fn=process, inputs=gr.Audio(type="filepath"), outputs=gr.outputs.Textbox(label="Generated Text") #examples=example_list, #cache_examples=False ) demo.launch(debug=False)