PierreHanna commited on
Commit
5558062
1 Parent(s): 72b0bca

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from simbals_apis_public_clients.clients.services import SimbalsAPIClient
2
+ import time
3
+ import json
4
+ import os
5
+ import gradio as gr
6
+
7
+ SIMBALS_GLOBAL_DB = 1
8
+ SIMBALS_MAIN_DATABASE = 2
9
+
10
+ def process(input_path):
11
+ # setup the client
12
+ client = SimbalsAPIClient(os.environ['TOKEN'], debug=True)
13
+ parameters = client.prepare_request("31415", audio_file=input_path)
14
+
15
+ # add audio features service with an available database
16
+ #parameters = client.add_audio_features(parameters, SIMBALS_MAIN_DATABASE)
17
+ parameters = client.add_tags(parameters, SIMBALS_MAIN_DATABASE)
18
+
19
+ # launch the request and test for ok/code values
20
+ ok, code, job_id = client.launch_request(parameters)
21
+ # try to get the results with obtained job_id. If code is 4, job is not finished. In all other cases, job is finished
22
+ for i in range(1000):
23
+ results=client.get_results(job_id)
24
+ if results[0] != 4:
25
+ print(json.dumps(results[1], indent=1))
26
+ #return json.dumps(results[1], indent=1)
27
+ output = json.dumps(results[1], indent=1)
28
+ trackname = results[1]["response"]["scanmatch"]['1']['partial_fast_matches'][0]['track']['title']
29
+ artistname = results[1]["response"]["scanmatch"]['1']['partial_fast_matches'][0]['artists'][0]['name']
30
+ return trackname+" by "+artistname
31
+ break
32
+ time.sleep(1)
33
+
34
+ demo = gr.Interface(fn=process,
35
+ inputs=gr.Audio(type="filepath"),
36
+ outputs=gr.outputs.Textbox(label="Generated Text")
37
+ #examples=example_list,
38
+ #cache_examples=False
39
+ )
40
+
41
+ demo.launch(debug=False)