janasumit2911 commited on
Commit
188f4cb
·
verified ·
1 Parent(s): baf681e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -93,13 +93,20 @@ def get_audio_data(url):
93
  return response.content
94
 
95
  def send_results_to_api(data, result_url):
96
- # Example function to send results to an API
97
  headers = {"Content-Type": "application/json"}
98
- response = requests.post(result_url, json=data, headers=headers)
99
- if response.status_code == 200:
100
- return response.json() # Return any response from the API if needed
101
- else:
102
- return {"error": f"Failed to send results to API: {response.status_code}"}
 
 
 
 
 
 
 
 
103
 
104
  def process_audio(params):
105
  try:
 
93
  return response.content
94
 
95
  def send_results_to_api(data, result_url):
 
96
  headers = {"Content-Type": "application/json"}
97
+ try:
98
+ response = requests.post(result_url, json=data, headers=headers)
99
+ response.raise_for_status() # Raise error for non-200 responses
100
+ return response.json() # Return any JSON response from the API
101
+ except requests.exceptions.HTTPError as http_err:
102
+ logging.error(f"HTTP error occurred: {http_err}")
103
+ return {"error": f"HTTP error occurred: {http_err}"}
104
+ except requests.exceptions.RequestException as req_err:
105
+ logging.error(f"Request error occurred: {req_err}")
106
+ return {"error": f"Request error occurred: {req_err}"}
107
+ except ValueError as val_err:
108
+ logging.error(f"Error decoding JSON response: {val_err}")
109
+ return {"error": f"Error decoding JSON response: {val_err}"}
110
 
111
  def process_audio(params):
112
  try: