Imageye commited on
Commit
2cf64dd
·
verified ·
1 Parent(s): 2b56299

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -13,7 +13,17 @@ def transcribe_audio(api_key, file_path):
13
  with open(file_path, "rb") as f:
14
  data = f.read()
15
  response = requests.post(API_URL, headers=headers, data=data)
16
- return response.json().get("text", "Error: Could not transcribe audio")
 
 
 
 
 
 
 
 
 
 
17
 
18
  # Function to get YouTube transcript
19
  def get_transcript(url):
 
13
  with open(file_path, "rb") as f:
14
  data = f.read()
15
  response = requests.post(API_URL, headers=headers, data=data)
16
+
17
+ try:
18
+ if response.status_code != 200:
19
+ return f"Error: Received status code {response.status_code}"
20
+ if not response.content:
21
+ return "Error: Empty response from server"
22
+ if 'application/json' not in response.headers.get('Content-Type', ''):
23
+ return "Error: Response is not in JSON format"
24
+ return response.json().get("text", "Error: Could not transcribe audio")
25
+ except requests.exceptions.JSONDecodeError:
26
+ return "Error: Could not decode JSON response"
27
 
28
  # Function to get YouTube transcript
29
  def get_transcript(url):