sachin commited on
Commit
a025dac
·
1 Parent(s): e592dcc

hadnle eror

Browse files
Files changed (1) hide show
  1. app.py +13 -22
app.py CHANGED
@@ -1,51 +1,42 @@
1
  import gradio as gr
2
  import requests
 
3
 
4
  # List of supported languages
5
- LANGUAGES = [
6
- "malayalam",
7
- "tamil",
8
- "telugu",
9
- "hindi",
10
- "kannada"
11
- ]
12
 
13
  # Function to extract language name
14
  def get_lang_name(lang_string):
15
  return lang_string.split("(")[0].strip().lower()
16
 
17
  def transcribe_api(audio_file, language):
18
-
19
- import os
20
-
21
- # Get the base URL (IP or domain) from environment variable
22
  base_url = os.getenv("DWANI_AI_API_BASE_URL")
23
 
24
  if not base_url:
25
- raise ValueError("DWANI_AI_API_BASE_URL environment variable is not set")
26
 
27
  # Define the endpoint path
28
  endpoint = "v1/transcribe/?language"
29
 
30
  # Construct the full API URL
31
- url = f"{base_url.rstrip('/')}{endpoint}"
32
- url = f"{url}={get_lang_name(language)}"
33
 
34
  headers = {
35
  "accept": "application/json",
36
  }
37
 
38
- # Open the file in binary mode
39
- with open(audio_file, 'rb') as f:
40
- files = {
41
- "file": (audio_file, f, "audio/x-wav")
42
- }
43
- try:
44
  response = requests.post(url, headers=headers, files=files)
45
  response.raise_for_status()
46
  return response.json()
47
- except requests.exceptions.RequestException as e:
48
- return f"Error: {str(e)}"
49
 
50
  # Create Gradio interface
51
  with gr.Blocks(title="Speech to Text API Interface") as demo:
 
1
  import gradio as gr
2
  import requests
3
+ import os
4
 
5
  # List of supported languages
6
+ LANGUAGES = ["malayalam", "tamil", "telugu", "hindi", "kannada"]
 
 
 
 
 
 
7
 
8
  # Function to extract language name
9
  def get_lang_name(lang_string):
10
  return lang_string.split("(")[0].strip().lower()
11
 
12
  def transcribe_api(audio_file, language):
13
+ # Get the base URL from environment variable
 
 
 
14
  base_url = os.getenv("DWANI_AI_API_BASE_URL")
15
 
16
  if not base_url:
17
+ return {"error": "DWANI_AI_API_BASE_URL environment variable is not set"}
18
 
19
  # Define the endpoint path
20
  endpoint = "v1/transcribe/?language"
21
 
22
  # Construct the full API URL
23
+ url = f"{base_url.rstrip('/')}/{endpoint}={get_lang_name(language)}"
 
24
 
25
  headers = {
26
  "accept": "application/json",
27
  }
28
 
29
+ try:
30
+ # Open the file in binary mode
31
+ with open(audio_file, 'rb') as f:
32
+ files = {
33
+ "file": (os.path.basename(audio_file), f, "audio/x-wav")
34
+ }
35
  response = requests.post(url, headers=headers, files=files)
36
  response.raise_for_status()
37
  return response.json()
38
+ except requests.exceptions.RequestException as e:
39
+ return {"error": str(e)}
40
 
41
  # Create Gradio interface
42
  with gr.Blocks(title="Speech to Text API Interface") as demo: