Samfredoly commited on
Commit
d1c663c
·
verified ·
1 Parent(s): 2960005

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -213,12 +213,14 @@ def upload_state_to_api(state: Dict[str, Any]) -> bool:
213
  log_message(f"✅ Successfully uploaded state file to API: {HF_STATE_FILE}", "INFO")
214
  return True
215
 
 
 
 
 
 
 
216
  except requests.exceptions.RequestException as e:
217
  log_message(f"❌ Failed to upload state file to API ({url}): {str(e)}", "ERROR")
218
- # 409 Conflict means the file already exists, which is fine for state updates
219
- if response.status_code == 409:
220
- log_message(f"⚠️ State file already exists on server (409 Conflict). Proceeding.", "WARNING")
221
- return True
222
  return False
223
  except Exception as e:
224
  log_message(f"❌ An unexpected error occurred during API state upload: {str(e)}", "ERROR")
@@ -238,10 +240,14 @@ def upload_transcription_to_api(json_output_path: str, matched_filename: str) ->
238
  log_message(f"✅ Successfully uploaded transcription to API: {os.path.basename(json_output_path)}", "INFO")
239
  return True
240
 
 
 
 
 
 
 
241
  except requests.exceptions.RequestException as e:
242
  log_message(f"❌ Failed to upload transcription to API ({url}): {str(e)}", "ERROR")
243
- if response.status_code == 409:
244
- log_message(f"⚠️ File already exists on server (409 Conflict).", "WARNING")
245
  return False
246
  except Exception as e:
247
  log_message(f"❌ An unexpected error occurred during API upload: {str(e)}", "ERROR")
@@ -695,4 +701,4 @@ async def stop_processing():
695
  if __name__ == "__main__":
696
  # This block is for local testing and won't be used in the final sandbox execution
697
  # but is good practice for a runnable script.
698
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
213
  log_message(f"✅ Successfully uploaded state file to API: {HF_STATE_FILE}", "INFO")
214
  return True
215
 
216
+ except requests.exceptions.HTTPError as e:
217
+ if hasattr(e, 'response') and e.response.status_code == 409:
218
+ log_message(f"⚠️ State file already exists on server (409 Conflict) - Treating as success.", "INFO")
219
+ return True
220
+ log_message(f"❌ Failed to upload state file to API ({url}): {str(e)}", "ERROR")
221
+ return False
222
  except requests.exceptions.RequestException as e:
223
  log_message(f"❌ Failed to upload state file to API ({url}): {str(e)}", "ERROR")
 
 
 
 
224
  return False
225
  except Exception as e:
226
  log_message(f"❌ An unexpected error occurred during API state upload: {str(e)}", "ERROR")
 
240
  log_message(f"✅ Successfully uploaded transcription to API: {os.path.basename(json_output_path)}", "INFO")
241
  return True
242
 
243
+ except requests.exceptions.HTTPError as e:
244
+ if hasattr(e, 'response') and e.response.status_code == 409:
245
+ log_message(f"⚠️ File already exists on server (409 Conflict) - Treating as success.", "INFO")
246
+ return True
247
+ log_message(f"❌ Failed to upload transcription to API ({url}): {str(e)}", "ERROR")
248
+ return False
249
  except requests.exceptions.RequestException as e:
250
  log_message(f"❌ Failed to upload transcription to API ({url}): {str(e)}", "ERROR")
 
 
251
  return False
252
  except Exception as e:
253
  log_message(f"❌ An unexpected error occurred during API upload: {str(e)}", "ERROR")
 
701
  if __name__ == "__main__":
702
  # This block is for local testing and won't be used in the final sandbox execution
703
  # but is good practice for a runnable script.
704
+ uvicorn.run(app, host="0.0.0.0", port=8000)