Update main.py
Browse files44 unmodified lines4546474849505118 unmodified lines707172737475764 unmodified lines8182838485868788899043 unmodified lines1341351361371381391402 unmodified lines14314414514614714814960 unmodified lines21021121221321421521621721813 unmodified lines23223323423523623723811 unmodified lines25025125225325425525625713 unmodified lines27127227327427527627730 unmodified lines3083093103113123133148 unmodified lines3233243253263273283299 unmodified lines33934034134234334434516 unmodified lines3623633643653663673686 unmodified lines3753763773783793803813828 unmodified lines39139239339439539639744 unmodified linesclass MeetingURL(BaseModel):meeting_url: strfinal_django_url: str# Функция для верификации токенаdef verify_token(token: str = Depends(oauth2_scheme)):18 unmodified lines@app.post("/connect_bot/")async def connect_bot(meeting_data: MeetingURL, token: str = Depends(verify_token)):meeting_url = meeting_data.meeting_urlfinal_django_url = meeting_data.final_django_urllogger.info(f"Connecting bot to the meeting at: {meeting_url}")url = recall_url4 unmodified lines}data = {"meeting_url": meeting_url,"bot_name": "Aspirity Notetaker","metadata": {"final_django_url": final_django_url,},}response = requests.post(url, headers=headers, json=data)43 unmodified linesasync with httpx.AsyncClient() as client:user_id = responseRetrieve.get('metadata', {}).get('user_id', None)event_id = responseRetrieve.get('metadata', {}).get('event_id', None)final_django_url = responseRetrieve.get('metadata', {}).get('final_django_url', None)data = {'video_url': str(responseRetrieve.get('video_url')),'final_url': "https://sabbah13-video-call-recording-and-transcription-9729a08.hf.space/transcript/",2 unmodified lines'bot_id': bot_id,'user_id': user_id,'event_id': event_id,'final_django_url': final_django_url,}headers = {'Authorization': f'Bearer {os.environ.get("HF_TOKEN")}'60 unmodified lines'event_id': event_id,}logger.info(f"Received JSON for transcription: {json_data.get('transcript')} Bot id: {json_data.get('bot_id')} Video url: {json_data.get('video_url')} Summary: {summary_answer} user_id: {user_id} event_id {event_id} will be sent to {json_data.get('final_django_url')}")response = requests.post(json_data.get('final_django_url'), headers=headers, json=data, verify=False)if response.status_code == 200:logger.info(f"The transcript has been sent.")13 unmodified linessemaphore = asyncio.Semaphore(1)async def send_video_for_transcription(file_content: bytes, filename: str, content_type: str, hash_path: str, final_django_url_my_video: str):async with semaphore:try:logger.info(f"Background task: sending video {filename} for transcription")11 unmodified lines'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,"final_django_url_my_video": final_django_url_my_video,}headers = {13 unmodified lines@app.post("/upload/")async def upload_video(file: UploadFile, hash_path: str = Form(...), final_django_url_my_video: str = Form(...), background_tasks: BackgroundTasks = BackgroundTasks(), token: str = Depends(verify_token)):try:logger.info(f"Received video: {file.filename}, hash_path: {hash_path}")30 unmodified linesfilename = file.filename # Извлечь имя файлаcontent_type = file.content_type # Извлечь тип содержимогоbackground_tasks.add_task(send_video_for_transcription, file_content, filename, content_type, hash_path, final_django_url_my_video)return JSONResponse(content={"status": "success", "message": "Video received. Processing will start soon."}, status_code=200)8 unmodified linestry:json_data = await request.json()logger.info(f"Received JSON for transcription: {json_data.get('transcript')} Video hash_path: {json_data.get('hash_path')} Final_django_uel {json_data.get('final_django_url_my_video')} ")summary_answer = get_completion_from_openai(str(base_promt + json_data.get('transcript')), 1024)9 unmodified lines"hash_path": json_data.get('hash_path'),}response = requests.post(json_data.get('final_django_url_my_video'), headers=headers, json=data, verify=False)if response.status_code == 200:logger.info(f"The transcript has been sent.")16 unmodified linesmeeting_date: struser_id: intevent_id: strfinal_django_url: strclass MeetingDeleteEvent(BaseModel):bot_id: str6 unmodified linesmeeting_date = meeting_data.meeting_dateuser_id = meeting_data.user_idevent_id = meeting_data.event_idfinal_django_url = meeting_data.final_django_urllogger.info(f"Connect bot to the meeting at: {meeting_url} in {meeting_date} with user {user_id} and event_id {event_id} final_django_url: {final_django_url}")headers = {"Authorization": recall_authorization_token,8 unmodified lines"metadata": {"user_id": user_id,"event_id": event_id,"final_django_url": final_django_url,},}44 unmodified lines45464748495018 unmodified lines6970717273744 unmodified lines7980818283848543 unmodified lines1291301311321331342 unmodified lines13713813914014114260 unmodified lines20320420520620720820921021113 unmodified lines22522622722822923023111 unmodified lines24324424524624724824913 unmodified lines26326426526626726826930 unmodified lines3003013023033043053068 unmodified lines3153163173183193203219 unmodified lines33133233333433533633716 unmodified lines3543553563573583596 unmodified lines3663673683693703713728 unmodified lines38138238338438538644 unmodified linesclass MeetingURL(BaseModel):meeting_url: str# Функция для верификации токенаdef verify_token(token: str = Depends(oauth2_scheme)):18 unmodified lines@app.post("/connect_bot/")async def connect_bot(meeting_data: MeetingURL, token: str = Depends(verify_token)):meeting_url = meeting_data.meeting_urllogger.info(f"Connecting bot to the meeting at: {meeting_url}")url = recall_url4 unmodified lines}data = {"meeting_url": meeting_url,"bot_name": "Aspirity Notetaker"}response = requests.post(url, headers=headers, json=data)43 unmodified linesasync with httpx.AsyncClient() as client:user_id = responseRetrieve.get('metadata', {}).get('user_id', None)event_id = responseRetrieve.get('metadata', {}).get('event_id', None)data = {'video_url': str(responseRetrieve.get('video_url')),'final_url': "https://sabbah13-video-call-recording-and-transcription-9729a08.hf.space/transcript/",2 unmodified lines'bot_id': bot_id,'user_id': user_id,'event_id': event_id,}headers = {'Authorization': f'Bearer {os.environ.get("HF_TOKEN")}'60 unmodified lines'event_id': event_id,}logger.info(f"Received JSON for transcription: {json_data.get('transcript')} Bot id: {json_data.get('bot_id')} Video url: {json_data.get('video_url')} Summary: {summary_answer} user_id: {user_id} event_id {event_id}")response = requests.post(note_taker_url_transcript, headers=headers, json=data, verify=False)if response.status_code == 200:logger.info(f"The transcript has been sent.")13 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")11 unmodified lines'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 = {13 unmodified lines@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}")30 unmodified linesfilename = 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)8 unmodified linestry:json_data = await request.json()logger.info(f"Received JSON for transcription: {json_data.get('transcript')} Video hash_path: {json_data.get('hash_path')} ")summary_answer = get_completion_from_openai(str(base_promt + json_data.get('transcript')), 1024)9 unmodified lines"hash_path": json_data.get('hash_path'),}response = requests.post(note_taker_url_transcript_my_video, headers=headers, json=data, verify=False)if response.status_code == 200:logger.info(f"The transcript has been sent.")16 unmodified linesmeeting_date: struser_id: intevent_id: strclass MeetingDeleteEvent(BaseModel):bot_id: str6 unmodified linesmeeting_date = meeting_data.meeting_dateuser_id = meeting_data.user_idevent_id = meeting_data.event_idlogger.info(f"Connect bot to the meeting at: {meeting_url} in {meeting_date} with user {user_id} and event_id {event_id}")headers = {"Authorization": recall_authorization_token,8 unmodified lines"metadata": {"user_id": user_id,"event_id": event_id,},}
main.py+10-21