Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,28 +5,31 @@ def encode_file_to_base64(file_path):
|
|
5 |
with open(file_path, "rb") as file:
|
6 |
return base64.b64encode(file.read()).decode('utf-8')
|
7 |
def bot_audio_interface(wav):
|
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 |
with gr.Blocks() as demo:
|
|
|
5 |
with open(file_path, "rb") as file:
|
6 |
return base64.b64encode(file.read()).decode('utf-8')
|
7 |
def bot_audio_interface(wav):
|
8 |
+
try:
|
9 |
+
print(wav)
|
10 |
+
url = "https://737e-104-199-156-254.ngrok-free.app/speech_to_speech"
|
11 |
+
b64 = encode_file_to_base64(wav)
|
12 |
+
data = {"b64": b64}
|
13 |
+
print('1')
|
14 |
+
response = requests.post(url, json=data)
|
15 |
+
print('2')
|
16 |
+
if response.status_code == 200:
|
17 |
+
json_response = response.json()
|
18 |
+
text = json_response.get("text")
|
19 |
+
response_text = json_response.get("response")
|
20 |
+
audio_base64 = json_response.get("audio_base64")
|
21 |
+
audio_data = base64.b64decode(audio_base64)
|
22 |
+
audio_path = "response_audio1.wav"
|
23 |
+
with open(audio_path, "wb") as audio_file:
|
24 |
+
audio_file.write(audio_data)
|
25 |
+
else:
|
26 |
+
print('kkk')
|
27 |
+
audio_path =''
|
28 |
+
text=''
|
29 |
+
response_text=''
|
30 |
+
return audio_path, text, response_text
|
31 |
+
except:
|
32 |
+
return 'response_audio.wav', 'text', 'response_text'
|
33 |
|
34 |
|
35 |
with gr.Blocks() as demo:
|