Update app.py
Browse files
app.py
CHANGED
|
@@ -27,15 +27,8 @@ from base64 import b64encode
|
|
| 27 |
from openai import OpenAI
|
| 28 |
from fuzzywuzzy import fuzz
|
| 29 |
|
| 30 |
-
from
|
| 31 |
-
from
|
| 32 |
-
import http.client
|
| 33 |
-
import socket
|
| 34 |
-
|
| 35 |
-
# Add these timeout settings before your route handler
|
| 36 |
-
socket.setdefaulttimeout(15) # 15 seconds timeout
|
| 37 |
-
http.client.HTTPConnection._http_vsn = 10
|
| 38 |
-
http.client.HTTPConnection._http_vsn_str = 'HTTP/1.0'
|
| 39 |
|
| 40 |
# start application
|
| 41 |
app = FastAPI()
|
|
@@ -109,7 +102,7 @@ receipt_sheet_headers = ['๋ฐํ์ผ', '์ํธ', '์ฌ์
์๋ฒํธ', 'ํฉ๊ณ๊ธ์ก
|
|
| 109 |
# at index 1 '๋ฑ๋ก ์ผ์', at last index '๋ช
ํจ๋ณด๊ธฐ'
|
| 110 |
business_card_sheet_headers = ['์ด๋ฆ', 'ํ์ฌ๋ช
', '์์ ๋ฐ ์ง์', '์ฃผ์', '์ ํ' ,'ํด๋ํฐ', 'ํฉ์ค','e-mail','ํํ์ด์ง']
|
| 111 |
sms_sheet_headers = ['๋ ์ง', '๊ณ์ข', '์
๊ธ', '์ถ๊ธ', '์์ก', '๋ฌธ์']
|
| 112 |
-
contact_sheet_headers = ['์ด๋ฆ', '์ ํ๋ฒํธ1', '์ ํ๋ฒํธ2', '์ ํ๋ฒํธ3', '์ด๋ฉ์ผ์ฃผ์1', '์ด๋ฉ
|
| 113 |
|
| 114 |
receipts_ss = 1395967745
|
| 115 |
business_cards_ss = 1733555840
|
|
@@ -587,23 +580,38 @@ async def update_fb_transaction(transaction_ref: firestore.DocumentReference, no
|
|
| 587 |
logging.error(f"Error updating transaction: {e}")
|
| 588 |
return {"status": f"Error: {str(e)}"}
|
| 589 |
|
| 590 |
-
async def
|
| 591 |
"""
|
| 592 |
-
|
|
|
|
| 593 |
"""
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 607 |
|
| 608 |
@app.post("/share-target-handle")
|
| 609 |
async def share_target_handle(request: Request):
|
|
@@ -622,22 +630,21 @@ async def share_target_handle(request: Request):
|
|
| 622 |
video_id = shared_data.split("youtu.be/")[1].split("?")[0]
|
| 623 |
|
| 624 |
if video_id:
|
| 625 |
-
|
| 626 |
-
if transcript:
|
| 627 |
-
first_entries = transcript[:2] if len(transcript) >= 2 else transcript
|
| 628 |
-
return {
|
| 629 |
-
"status": "success",
|
| 630 |
-
"message": "Transcript retrieved successfully",
|
| 631 |
-
"transcript": first_entries
|
| 632 |
-
}
|
| 633 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
except Exception as e:
|
| 635 |
-
logging.error(f"Error processing YouTube
|
| 636 |
return {
|
| 637 |
"status": "error",
|
| 638 |
-
"message": f"Failed to process
|
| 639 |
}
|
| 640 |
-
|
| 641 |
return {"status": "success", "message": "Data logged successfully"}
|
| 642 |
|
| 643 |
@app.post("/check-userdoc")
|
|
|
|
| 27 |
from openai import OpenAI
|
| 28 |
from fuzzywuzzy import fuzz
|
| 29 |
|
| 30 |
+
from googleapiclient.discovery import build
|
| 31 |
+
from google.oauth2 import service_account
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# start application
|
| 34 |
app = FastAPI()
|
|
|
|
| 102 |
# at index 1 '๋ฑ๋ก ์ผ์', at last index '๋ช
ํจ๋ณด๊ธฐ'
|
| 103 |
business_card_sheet_headers = ['์ด๋ฆ', 'ํ์ฌ๋ช
', '์์ ๋ฐ ์ง์', '์ฃผ์', '์ ํ' ,'ํด๋ํฐ', 'ํฉ์ค','e-mail','ํํ์ด์ง']
|
| 104 |
sms_sheet_headers = ['๋ ์ง', '๊ณ์ข', '์
๊ธ', '์ถ๊ธ', '์์ก', '๋ฌธ์']
|
| 105 |
+
contact_sheet_headers = ['์ด๋ฆ', '์ ํ๋ฒํธ1', '์ ํ๋ฒํธ2', '์ ํ๋ฒํธ3', '์ด๋ฉ์ผ์ฃผ์1', '์ด๋ฉ์ผ์ฃผ์2', '์ด๋ฉ์ผ์ฃผ์3', '๊ทธ๋ฃน']
|
| 106 |
|
| 107 |
receipts_ss = 1395967745
|
| 108 |
business_cards_ss = 1733555840
|
|
|
|
| 580 |
logging.error(f"Error updating transaction: {e}")
|
| 581 |
return {"status": f"Error: {str(e)}"}
|
| 582 |
|
| 583 |
+
async def get_youtube_captions(video_id: str) -> List[dict]:
|
| 584 |
"""
|
| 585 |
+
# Necessary for handling video transcripts when users want to extract information from YouTube videos
|
| 586 |
+
# Uses official YouTube Data API instead of third-party transcript API for better reliability
|
| 587 |
"""
|
| 588 |
+
try:
|
| 589 |
+
# Build YouTube service using existing credentials
|
| 590 |
+
youtube_service = build('youtube', 'v3', credentials=APICredential)
|
| 591 |
+
|
| 592 |
+
# Get caption tracks available for the video
|
| 593 |
+
captions_response = youtube_service.captions().list(
|
| 594 |
+
part='snippet',
|
| 595 |
+
videoId=video_id
|
| 596 |
+
).execute()
|
| 597 |
+
|
| 598 |
+
if not captions_response.get('items'):
|
| 599 |
+
return []
|
| 600 |
+
|
| 601 |
+
# Get the first available caption track (usually the default one)
|
| 602 |
+
caption_id = captions_response['items'][0]['id']
|
| 603 |
+
|
| 604 |
+
# Download the caption track
|
| 605 |
+
caption_track = youtube_service.captions().download(
|
| 606 |
+
id=caption_id,
|
| 607 |
+
tfmt='srt' # Request in SRT format
|
| 608 |
+
).execute()
|
| 609 |
+
|
| 610 |
+
return caption_track
|
| 611 |
+
|
| 612 |
+
except Exception as e:
|
| 613 |
+
logging.error(f"Error getting YouTube captions: {str(e)}")
|
| 614 |
+
return []
|
| 615 |
|
| 616 |
@app.post("/share-target-handle")
|
| 617 |
async def share_target_handle(request: Request):
|
|
|
|
| 630 |
video_id = shared_data.split("youtu.be/")[1].split("?")[0]
|
| 631 |
|
| 632 |
if video_id:
|
| 633 |
+
captions = await get_youtube_captions(video_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
|
| 635 |
+
return {
|
| 636 |
+
"status": "success",
|
| 637 |
+
"message": "Captions retrieved successfully",
|
| 638 |
+
"captions": captions
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
except Exception as e:
|
| 642 |
+
logging.error(f"Error processing YouTube captions: {str(e)}")
|
| 643 |
return {
|
| 644 |
"status": "error",
|
| 645 |
+
"message": f"Failed to process captions: {str(e)}"
|
| 646 |
}
|
| 647 |
+
|
| 648 |
return {"status": "success", "message": "Data logged successfully"}
|
| 649 |
|
| 650 |
@app.post("/check-userdoc")
|