Spaces:
Runtime error
Runtime error
File size: 3,794 Bytes
5558062 830f8b5 99236eb 812d7ec 830f8b5 812d7ec 830f8b5 812d7ec 830f8b5 812d7ec 830f8b5 812d7ec 9099754 830f8b5 9099754 830f8b5 9099754 830f8b5 8073c1f 5a85c5b 0f671a0 5558062 ffecd2a d24216f 5558062 0f671a0 356b9b0 789a241 356b9b0 0f671a0 8073c1f 0f671a0 5a85c5b cb32366 387a541 5c10997 cb32366 387a541 8073c1f 5a85c5b e89f7b1 5a85c5b 28b55f2 356b9b0 5558062 |
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
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)
parameters = client.prepare_request("31415", audio_file=input_path)
# 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)
break
time.sleep(1)
res = results[1]["response"]["tagging"]["2"]
dict_moods = {}
for m in res['moods']:
dict_moods[m['name']] = m['probability']
dict_desc={}
for d in res['music_descriptors']:
dict_desc[d['name']] = d['value']
genres={}
for d in res['genres']:
genres[d['name']] = d['probability']
themes = {}
for d in res['themes']:
themes[d['name']]= d['probability']
instruments = {}
for d in res['instruments']:
instruments[d['name']] = d['probability']
timbres = []
for d in res['timbres']:
timbres.append((d['name'],d['probability']))
print(timbres)
vocalgender = [res['vocal_gender'][0]['name'], res['vocal_gender'][0]['probability']]
print(vocalgender)
audioquality = [res['audio_quality'][0]['name'], res['audio_quality'][0]['probability']]
print(audioquality)
return dict_moods, genres, instruments, themes, [dict_desc['Vocal/Instrumental']]
'''
demo = gr.Interface(fn=process,
inputs=gr.Audio(type="filepath"),
outputs=gr.outputs.Label(label="Moods"),
#outputs=gr.outputs.Textbox(label="Generated Text")
#examples=example_list,
#cache_examples=False
)
'''
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
with gr.Row():
audio_input = gr.Audio(type="filepath", label='Audio Input')
with gr.Row():
analyze_btn = gr.Button('Analyze File')
with gr.Row():
dict_moods=gr.Label(label="Moods")
themes=gr.Label(label="Themes")
genres = gr.Label(label="Genres")
instruments = gr.Label(label="Instruments")
#dict_desc = gr.Textbox(label="music desc")
'''
themes = gr.Dataset(components=[gr.Textbox(visible=False)],
label="type de tags",
samples=[
["Tag1"],
["Tag2"],
["Tag3"],
["Tag4"]
],
)
'''
#themes = gr.Dataset(components=[gr.Textbox(visible=False)],label="type de tags")
vocalinstru = gr.Textbox(label="Vocal/Instrumental"),
analyze_btn.click(process, inputs=[audio_input], outputs=[dict_moods, genres, instruments, themes, vocalinstru])
#audio_input.submit(process, inputs=[audio_input], outputs=[moods]) # pas de sens !
demo.launch(debug=False) |