Spaces:
Sleeping
Sleeping
Update rag_chain.py
Browse files- rag_chain.py +14 -10
rag_chain.py
CHANGED
@@ -51,15 +51,18 @@ Answer:""",
|
|
51 |
input_variables=["context", "question"],
|
52 |
)
|
53 |
|
54 |
-
|
55 |
-
def fetch_transcript(video_id: str, proxies: dict = None) -> str:
|
56 |
try:
|
57 |
-
#
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
63 |
|
64 |
transcript = YouTubeTranscriptApi.get_transcript(video_id, languages=["en", "hi"])
|
65 |
return " ".join([t["text"] for t in transcript])
|
@@ -69,9 +72,10 @@ def fetch_transcript(video_id: str, proxies: dict = None) -> str:
|
|
69 |
except Exception as e:
|
70 |
raise Exception(f"Error fetching transcript: {str(e)}")
|
71 |
|
|
|
72 |
# Build RAG chain from transcript
|
73 |
-
def build_chain(video_id: str
|
74 |
-
text = fetch_transcript(video_id
|
75 |
|
76 |
splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
|
77 |
docs = splitter.create_documents([text])
|
|
|
51 |
input_variables=["context", "question"],
|
52 |
)
|
53 |
|
54 |
+
def fetch_transcript(video_id: str) -> str:
|
|
|
55 |
try:
|
56 |
+
# ✅ Define your proxy here
|
57 |
+
proxies = {
|
58 |
+
"http": "http://219.65.73.81:80",
|
59 |
+
"https": "http://219.65.73.81:80"
|
60 |
+
}
|
61 |
+
|
62 |
+
# Patch requests session with proxy
|
63 |
+
session = requests.Session()
|
64 |
+
session.proxies.update(proxies)
|
65 |
+
YouTubeTranscriptApi._requests = session # monkey patch
|
66 |
|
67 |
transcript = YouTubeTranscriptApi.get_transcript(video_id, languages=["en", "hi"])
|
68 |
return " ".join([t["text"] for t in transcript])
|
|
|
72 |
except Exception as e:
|
73 |
raise Exception(f"Error fetching transcript: {str(e)}")
|
74 |
|
75 |
+
|
76 |
# Build RAG chain from transcript
|
77 |
+
def build_chain(video_id: str) -> RetrievalQA:
|
78 |
+
text = fetch_transcript(video_id)
|
79 |
|
80 |
splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
|
81 |
docs = splitter.create_documents([text])
|