Ra-Is commited on
Commit
f6c1536
·
verified ·
1 Parent(s): 8e995fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -1,14 +1,14 @@
1
  import requests
2
- import json
3
  import gradio as gr
4
  import os
5
 
6
- def send_audio_to_laravel(audio):
7
- url = os.getenv("BASE_URL")
8
 
9
  # Save audio to a temporary file
10
  temp_audio_path = "temp_audio.wav"
11
- audio.save(temp_audio_path)
 
12
 
13
  # Prepare form data for request
14
  files = {
@@ -19,16 +19,15 @@ def send_audio_to_laravel(audio):
19
  }
20
 
21
  response = requests.post(url, files=files, data=data)
22
-
23
  return response.json()
24
 
25
  # Gradio interface for recording speech
26
  iface = gr.Interface(
27
- fn=send_audio_to_laravel,
28
- inputs=gr.Audio(type="file"), # Removed 'source' parameter
29
  outputs="text",
30
  title="Speech Translation",
31
- description="Record speech and send for processing"
32
  )
33
 
34
  iface.launch()
 
1
  import requests
 
2
  import gradio as gr
3
  import os
4
 
5
+ def send_audio(audio):
6
+ url = os.getenv("BASE_URL")
7
 
8
  # Save audio to a temporary file
9
  temp_audio_path = "temp_audio.wav"
10
+ with open(temp_audio_path, 'wb') as f:
11
+ f.write(audio.read())
12
 
13
  # Prepare form data for request
14
  files = {
 
19
  }
20
 
21
  response = requests.post(url, files=files, data=data)
 
22
  return response.json()
23
 
24
  # Gradio interface for recording speech
25
  iface = gr.Interface(
26
+ fn=send_audio,
27
+ inputs=gr.Audio(source="microphone", type="file"),
28
  outputs="text",
29
  title="Speech Translation",
30
+ description="Record speech and send for processing"
31
  )
32
 
33
  iface.launch()