lodhrangpt commited on
Commit
f3f5ab6
·
verified ·
1 Parent(s): 042bc75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -15,31 +15,30 @@ def transcribe(audio_path):
15
  with open(audio_path, "rb") as audio_file:
16
  audio_data = audio_file.read()
17
 
18
- # Groq API endpoint for audio transcription
19
- groq_api_endpoint = "https://api.groq.com/openai/v1/audio/transcriptions"
 
20
 
 
21
  headers = {
22
- "Authorization": "Bearer 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",
23
- }
24
-
25
- files = {
26
- 'file': ('audio.wav', audio_data, 'audio/wav'),
27
  }
 
28
  data = {
29
- 'model': 'whisper-large-v3-turbo',
30
  'response_format': 'json',
31
  'language': 'en',
32
  }
33
 
34
- # Send audio to Groq API
35
  response = requests.post(groq_api_endpoint, headers=headers, files=files, data=data)
36
-
37
  if response.status_code == 200:
38
  result = response.json()
39
- transcript = result.get("text", "No transcription available.")
40
- return generate_notes(transcript)
41
  else:
42
- return f"Error: {response.status_code}, {response.text}"
 
 
43
 
44
  # Function to generate notes and questions
45
  def generate_notes(transcript):
 
15
  with open(audio_path, "rb") as audio_file:
16
  audio_data = audio_file.read()
17
 
18
+ def transcribe(audio_path):
19
+ with open(audio_path, "rb") as audio_file:
20
+ audio_data = audio_file.read()
21
 
22
+ groq_api_endpoint = "https://api.groq.com/openai/v1/audio/transcriptions"
23
  headers = {
24
+ "Authorization": "Bearer YOUR_GROQ_API_KEY", # Replace with your actual API key
 
 
 
 
25
  }
26
+ files = {'file': ('audio.wav', audio_data, 'audio/wav')}
27
  data = {
28
+ 'model': 'whisper-large-v3-turbo',
29
  'response_format': 'json',
30
  'language': 'en',
31
  }
32
 
33
+ # Send audio to Groq API and handle errors
34
  response = requests.post(groq_api_endpoint, headers=headers, files=files, data=data)
 
35
  if response.status_code == 200:
36
  result = response.json()
37
+ return result.get("text", "No transcription available.")
 
38
  else:
39
+ error_msg = response.json().get("error", {}).get("message", "Unknown error.")
40
+ return f"API Error: {error_msg}"
41
+
42
 
43
  # Function to generate notes and questions
44
  def generate_notes(transcript):