Update main.py
Browse files196 unmodified lines1971981992002012022032042052062 unmodified lines20921021121221321421510 unmodified lines22622722822923023123234 unmodified lines267268269270271272273274275276277278279196 unmodified linessemaphore = asyncio.Semaphore(1)async def send_video_for_transcription(file_content: bytes, filename: str, content_type: str, hash_path: str):async with semaphore:try:logger.info(f"Background task: sending video {filename} for transcription")run_time = api.get_space_runtime(repo_id=repo_id)if run_time.stage != 'RUNNING':2 unmodified lineslogger.info('Transcription space is running, sending file')async with httpx.AsyncClient() as client:files = {'file': (filename, file_content, content_type)}data = {'final_url': "https://sabbah13-video-call-recording-and-transcription-9729a08.hf.space/transcript/video-file/",10 unmodified linesresponse = await client.post(transcribation_url, files=files, data=data, headers=headers)if response.status_code == 200:logger.info(f"Video successfully sent for transcription {filename}")else:logger.error(f"Error sending video for transcription: {response.text}")34 unmodified lines# logger.info(f"Video successfully sent for transcription {file.filename}")# else:# logger.error(f"Error sending video for transcription: {response.text}")file_content = await file.read() # Прочитать весь файлfilename = file.filename # Извлечь имя файлаcontent_type = file.content_type # Извлечь тип содержимогоbackground_tasks.add_task(send_video_for_transcription, file_content, filename, content_type, hash_path)return JSONResponse(content={"status": "success", "message": "Video received. Processing will start soon."}, status_code=200)196 unmodified lines1971981992002012022032042052062 unmodified lines20921021121221321421510 unmodified lines22622722822923023123234 unmodified lines267268269270271272273274196 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':2 unmodified lineslogger.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/",10 unmodified linesresponse = 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}")34 unmodified lines# logger.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+5-10