Update main.py
Browse files11 unmodified lines121314151617161 unmodified lines17918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922011 unmodified linesfrom gigiachat_requests import get_access_token, get_completion_from_gigachat, get_number_of_tokens, process_transcribation_with_gigachatfrom openai_requests import get_completion_from_openai, process_transcribation_with_assistantapi = HfApi()app = FastAPI()161 unmodified linesasync def send_video_for_transcription(file: UploadFile, hash_path: str):try:logging.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':await restart_and_check_space(repo_id) # Перезапуск транскрибационного сервиса, если он не запущенelse:logging.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:logging.info("Video successfully sent for transcription")else:logging.error(f"Error sending video for transcription: {response.text}")except Exception as e:logging.error(f"Error in background task: {e}")11 unmodified lines121314151617181920161 unmodified lines18218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322411 unmodified linesfrom gigiachat_requests import get_access_token, get_completion_from_gigachat, get_number_of_tokens, process_transcribation_with_gigachatfrom openai_requests import get_completion_from_openai, process_transcribation_with_assistantimport asynciofrom asyncio import Semaphoreapi = HfApi()app = FastAPI()161 unmodified linessemaphore = asyncio.Semaphore(1)async def send_video_for_transcription(file: UploadFile, hash_path: str):async with semaphore:try:logging.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':await restart_and_check_space(repo_id) # Перезапуск транскрибационного сервиса, если он не запущенelse:logging.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:logging.info("Video successfully sent for transcription")else:logging.error(f"Error sending video for transcription: {response.text}")except Exception as e:logging.error(f"Error in background task: {e}")
main.py+36-32