@@ -54,11 +54,12 @@ def unzip_file(zip_src, dst_dir):
5454async def audio_count_table_api (table_name : str = None ):
5555 try :
5656 index_client , conn , cursor = audio_init_conn ()
57- rows_milvus , rows_mysql = audio_count_table (index_client , conn , cursor , table_name )
57+ rows_milvus , rows_mysql = audio_count_table (
58+ index_client , conn , cursor , table_name )
5859 return {'status' : True , 'msg' : {'rows_milvus' : rows_milvus , 'rows_mysql' : rows_mysql }}, 200
5960 except Exception as e :
6061 logging .error (e )
61- return {'status' : False , 'msg' :e }, 400
62+ return {'status' : False , 'msg' : e }, 400
6263
6364
6465@app .get ('/getAudio' )
@@ -68,7 +69,7 @@ async def audio_endpoint(audio: str):
6869 return FileResponse (audio )
6970 except Exception as e :
7071 logging .error (e )
71- return {'status' : False , 'msg' :e }, 400
72+ return {'status' : False , 'msg' : e }, 400
7273
7374
7475@app .get ('/getSpectrogram' )
@@ -78,7 +79,7 @@ async def spectrogram_endpoint(image: str):
7879 return FileResponse (image )
7980 except Exception as e :
8081 logging .error (e )
81- return {'status' : False , 'msg' :e }, 400
82+ return {'status' : False , 'msg' : e }, 400
8283
8384
8485@app .post ('/audio/insert' )
@@ -91,17 +92,19 @@ async def do_insert_audio_api(file: bytes = File(...), table_name: str = None):
9192
9293 os .makedirs (audio_UPLOAD_PATH + "/" + table_name )
9394 fname_path = audio_UPLOAD_PATH + "/" + table_name + "/" + "demo_audio.zip"
94- with open (fname_path ,'wb' ) as f :
95+ with open (fname_path , 'wb' ) as f :
9596 f .write (file )
9697
97- audio_path = unzip_file (fname_path , audio_UPLOAD_PATH + "/" + table_name )
98+ audio_path = unzip_file (
99+ fname_path , audio_UPLOAD_PATH + "/" + table_name )
98100 os .remove (fname_path )
99101
100- info = audio_insert_audio (index_client , conn , cursor , table_name , audio_UPLOAD_PATH + "/" + table_name )
102+ info = audio_insert_audio (
103+ index_client , conn , cursor , table_name , audio_UPLOAD_PATH + "/" + table_name )
101104 return {'status' : True , 'msg' : info }, 200
102105 except Exception as e :
103106 logging .error (e )
104- return {'status' : False , 'msg' :e }, 400
107+ return {'status' : False , 'msg' : e }, 400
105108
106109
107110@app .post ('/audio/search' )
@@ -114,8 +117,9 @@ async def do_search_audio_api(request: Request, audio: UploadFile = File(...), t
114117
115118 index_client , conn , cursor = audio_init_conn ()
116119 host = request .headers ['host' ]
117- milvus_ids , milvus_distance , audio_ids = audio_search_audio (index_client , conn , cursor , table_name , filename )
118-
120+ milvus_ids , milvus_distance , audio_ids = audio_search_audio (
121+ index_client , conn , cursor , table_name , filename )
122+
119123 results = []
120124 for i in range (len (milvus_ids )):
121125 re = {
@@ -128,8 +132,7 @@ async def do_search_audio_api(request: Request, audio: UploadFile = File(...), t
128132 return {'status' : True , 'msg' : results }, 200
129133 except Exception as e :
130134 logging .error (e )
131- return {'status' : False , 'msg' :e }, 400
132-
135+ return {'status' : False , 'msg' : e }, 400
133136
134137
135138if __name__ == '__main__' :
0 commit comments