@@ -54,11 +54,12 @@ def unzip_file(zip_src, dst_dir):
54
54
async def audio_count_table_api (table_name : str = None ):
55
55
try :
56
56
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 )
58
59
return {'status' : True , 'msg' : {'rows_milvus' : rows_milvus , 'rows_mysql' : rows_mysql }}, 200
59
60
except Exception as e :
60
61
logging .error (e )
61
- return {'status' : False , 'msg' :e }, 400
62
+ return {'status' : False , 'msg' :e }, 400
62
63
63
64
64
65
@app .get ('/getAudio' )
@@ -68,7 +69,7 @@ async def audio_endpoint(audio: str):
68
69
return FileResponse (audio )
69
70
except Exception as e :
70
71
logging .error (e )
71
- return {'status' : False , 'msg' :e }, 400
72
+ return {'status' : False , 'msg' :e }, 400
72
73
73
74
74
75
@app .get ('/getSpectrogram' )
@@ -78,7 +79,7 @@ async def spectrogram_endpoint(image: str):
78
79
return FileResponse (image )
79
80
except Exception as e :
80
81
logging .error (e )
81
- return {'status' : False , 'msg' :e }, 400
82
+ return {'status' : False , 'msg' :e }, 400
82
83
83
84
84
85
@app .post ('/audio/insert' )
@@ -91,17 +92,19 @@ async def do_insert_audio_api(file: bytes = File(...), table_name: str = None):
91
92
92
93
os .makedirs (audio_UPLOAD_PATH + "/" + table_name )
93
94
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 :
95
96
f .write (file )
96
97
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 )
98
100
os .remove (fname_path )
99
101
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 )
101
104
return {'status' : True , 'msg' : info }, 200
102
105
except Exception as e :
103
106
logging .error (e )
104
- return {'status' : False , 'msg' :e }, 400
107
+ return {'status' : False , 'msg' :e }, 400
105
108
106
109
107
110
@app .post ('/audio/search' )
@@ -114,8 +117,9 @@ async def do_search_audio_api(request: Request, audio: UploadFile = File(...), t
114
117
115
118
index_client , conn , cursor = audio_init_conn ()
116
119
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
+
119
123
results = []
120
124
for i in range (len (milvus_ids )):
121
125
re = {
@@ -128,8 +132,7 @@ async def do_search_audio_api(request: Request, audio: UploadFile = File(...), t
128
132
return {'status' : True , 'msg' : results }, 200
129
133
except Exception as e :
130
134
logging .error (e )
131
- return {'status' : False , 'msg' :e }, 400
132
-
135
+ return {'status' : False , 'msg' : e }, 400
133
136
134
137
135
138
if __name__ == '__main__' :
0 commit comments