Update main.py
Browse files79 unmodified lines80818283848543 unmodified lines1291301311321331342 unmodified lines13713813914014114260 unmodified lines20320420520620720820921021113 unmodified lines22522622722822923023112 unmodified lines24424524624724824913 unmodified lines26326426526626726826930 unmodified lines3003013023033043053068 unmodified lines3153163173183193203219 unmodified lines33133233333433533633716 unmodified lines3543553563573583596 unmodified lines3663673683693703713728 unmodified lines38138238338438538679 unmodified linesdata = {"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")12 unmodified lines'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,},}79 unmodified lines80818283848586878843 unmodified lines1321331341351361371382 unmodified lines14114214314414514614760 unmodified lines20820921021121221321421521613 unmodified lines23023123223323423523612 unmodified lines24925025125225325425513 unmodified lines26927027127227327427530 unmodified lines3063073083093103113128 unmodified lines3213223233243253263279 unmodified lines33733833934034134234316 unmodified lines3603613623633643653666 unmodified lines3733743753763773783793808 unmodified lines38939039139239339439579 unmodified linesdata = {"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")12 unmodified lines'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,},}
main.py+17-8