mohan696matlab commited on
Commit
86a618f
Β·
1 Parent(s): 394c2b1

new app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -33,20 +33,19 @@ def translate_audio(audio, SARVAM_API_KEY):
33
  files = {'file': ('audiofile.wav', chunk_buffer, 'audio/wav')}
34
 
35
  try:
36
- # Make the POST request to the API
37
  response = requests.post(api_url, headers=headers, files=files, data=model_data)
 
38
  if response.status_code == 200 or response.status_code == 201:
39
  response_data = response.json()
40
  transcript = response_data.get("transcript", "")
 
 
41
  else:
42
- # Handle failed requests
43
- print(f"failed with status code: {response.status_code}")
44
- print("Response:", response.text)
45
  except Exception as e:
46
- # Handle any exceptions during the request
47
- print(f"Error processing chunk {e}")
48
  finally:
49
- # Ensure the buffer is closed after processing
50
  chunk_buffer.close()
51
 
52
  return transcript
@@ -81,6 +80,8 @@ def stream_transcribe(history, new_chunk, SARVAM_API_KEY):
81
  history = history + '\n' + transcription
82
 
83
  return history, history, f"{latency:.2f}"
 
 
84
  except Exception as e:
85
  print(f"Error during Transcription: {e}")
86
  return history, str(e), "Error"
@@ -103,6 +104,8 @@ with gr.Blocks(theme=gr.themes.Glass()) as microphone:
103
 
104
  gr.Markdown(
105
  """
 
 
106
  ### πŸ”‘ Sarvam AI API Key Required
107
  To use this app, you need a free API key from [Sarvam AI](https://sarvam.ai).
108
 
 
33
  files = {'file': ('audiofile.wav', chunk_buffer, 'audio/wav')}
34
 
35
  try:
 
36
  response = requests.post(api_url, headers=headers, files=files, data=model_data)
37
+
38
  if response.status_code == 200 or response.status_code == 201:
39
  response_data = response.json()
40
  transcript = response_data.get("transcript", "")
41
+ elif response.status_code == 401 or response.status_code == 403:
42
+ raise ValueError("❌ Invalid API key. Please check your Sarvam AI key.")
43
  else:
44
+ raise RuntimeError(f"❌ Request failed with status code: {response.status_code}. Details: {response.text}")
45
+
 
46
  except Exception as e:
47
+ raise e # Let the caller handle it
 
48
  finally:
 
49
  chunk_buffer.close()
50
 
51
  return transcript
 
80
  history = history + '\n' + transcription
81
 
82
  return history, history, f"{latency:.2f}"
83
+ except ValueError as ve:
84
+ return history, str(ve), "Invalid Key"
85
  except Exception as e:
86
  print(f"Error during Transcription: {e}")
87
  return history, str(e), "Error"
 
104
 
105
  gr.Markdown(
106
  """
107
+ ### This app is designed to **transcribe and translate simultaneously from multiple Indian languages**. It supports **22 Indian languages**, including **Hindi, Oriya, Tamil, Telugu, Gujarati**, and more. It can **translate the transcribed text in real-time to English**, making it incredibly useful for multilingual audio processing.
108
+
109
  ### πŸ”‘ Sarvam AI API Key Required
110
  To use this app, you need a free API key from [Sarvam AI](https://sarvam.ai).
111