Ra-Is commited on
Commit
7026386
1 Parent(s): 65b1d66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -2,13 +2,12 @@ import gradio as gr
2
  import requests
3
  import os
4
 
5
- def send_audio_to_laravel(audio):
6
  url = os.getenv("TRANSLATION_URL")
7
 
8
  if audio is None:
9
  return {"error": "No audio file provided"}
10
 
11
- # If `audio` is a file-like object
12
  try:
13
  if isinstance(audio, bytes):
14
  # If audio is a bytes object, save it to a temporary file
@@ -28,18 +27,23 @@ def send_audio_to_laravel(audio):
28
  }
29
 
30
  response = requests.post(url, files=files, data=data)
31
- return response.json()
 
 
 
 
 
32
 
33
  except Exception as e:
34
  return {"error": str(e)}
35
 
36
  # Gradio interface for recording speech
37
  iface = gr.Interface(
38
- fn=send_audio_to_laravel,
39
  inputs=gr.Audio(type="filepath"), # Expect a file path or file-like object
40
  outputs="text",
41
  title="Speech Translation",
42
- description="Record speech and send it to Laravel for processing.",
43
  )
44
 
45
- iface.launch()
 
2
  import requests
3
  import os
4
 
5
+ def send_audio(audio):
6
  url = os.getenv("TRANSLATION_URL")
7
 
8
  if audio is None:
9
  return {"error": "No audio file provided"}
10
 
 
11
  try:
12
  if isinstance(audio, bytes):
13
  # If audio is a bytes object, save it to a temporary file
 
27
  }
28
 
29
  response = requests.post(url, files=files, data=data)
30
+ response_json = response.json()
31
+
32
+ # Extract the translation part
33
+ translation = response_json.get('data', {}).get('translation', 'No translation available')
34
+
35
+ return translation
36
 
37
  except Exception as e:
38
  return {"error": str(e)}
39
 
40
  # Gradio interface for recording speech
41
  iface = gr.Interface(
42
+ fn=send_audio,
43
  inputs=gr.Audio(type="filepath"), # Expect a file path or file-like object
44
  outputs="text",
45
  title="Speech Translation",
46
+ description="Record speech and send for processing.",
47
  )
48
 
49
+ iface.launch()