Update main.py
Browse files197 unmodified lines19819920020120220320420520620722 unmodified lines230231232233234235236237238239240241242243244245246197 unmodified linessemaphore = asyncio.Semaphore(1)# Функция для отправки видео на транскрипциюasync def send_video_for_transcription(file: UploadFile, hash_path: str):async with semaphore:try:logger.info(f"Background task: sending video {file.filename} for transcription")run_time = api.get_space_runtime(repo_id=repo_id)if run_time.stage != 'RUNNING':22 unmodified lineslogger.info(f"Video successfully sent for transcription {file.filename}")else:logger.error(f"Error sending video for transcription: {response.text}")except Exception as e:logger.error(f"Error in background task: {e}")@app.post("/upload/")async def upload_video(file: UploadFile, hash_path: str = Form(...), background_tasks: BackgroundTasks = BackgroundTasks(), token: str = Depends(verify_token)):try:logger.info(f"Received video: {file.filename}, hash_path: {hash_path}")background_tasks.add_task(send_video_for_transcription, file, hash_path)return JSONResponse(content={"status": "success", "message": "Video received. Processing will start soon."}, status_code=200)197 unmodified lines19819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424522 unmodified lines268269270271272273274275276197 unmodified linessemaphore = asyncio.Semaphore(1)# Функция для отправки видео на транскрипцию# async def send_video_for_transcription(file: UploadFile, hash_path: str):# async with semaphore:# try:# logger.info(f"Background task: sending video {file.filename} for transcription")# run_time = api.get_space_runtime(repo_id=repo_id)# if run_time.stage != 'RUNNING':# restart_and_check_space(repo_id) # Перезапуск транскрибационного сервиса, если он не запущен# else:# logger.info('Transcription space is running, sending file')# async with httpx.AsyncClient() as client:# files = {# 'file': (file.filename, file.file, file.content_type)# }# data = {# 'final_url': "https://sabbah13-video-call-recording-and-transcription-9729a08.hf.space/transcript/video-file/",# 'max_speakers': 10,# 'min_speakers': 1,# "hash_path": hash_path# }# headers = {# "Authorization": f'Bearer {os.environ.get("HF_TOKEN")}'# }# # Отправляем видео на сервер транскрибации# response = await client.post(transcribation_url, files=files, data=data, headers=headers)# if response.status_code == 200:# logger.info(f"Video successfully sent for transcription {file.filename}")# else:# logger.error(f"Error sending video for transcription: {response.text}")# except Exception as e:# logger.error(f"Error in background task: {e}")@app.post("/upload/")async def upload_video(file: UploadFile, hash_path: str = Form(...), background_tasks: BackgroundTasks = BackgroundTasks(), token: str = Depends(verify_token)):try:logger.info(f"Received video: {file.filename}, hash_path: {hash_path}")run_time = api.get_space_runtime(repo_id=repo_id)if run_time.stage != 'RUNNING':22 unmodified lineslogger.info(f"Video successfully sent for transcription {file.filename}")else:logger.error(f"Error sending video for transcription: {response.text}")# background_tasks.add_task(send_video_for_transcription, file, hash_path)return JSONResponse(content={"status": "success", "message": "Video received. Processing will start soon."}, status_code=200)
main.py+44-14