neel692 commited on
Commit
409b49f
·
verified ·
1 Parent(s): 5d3ee94

proxy added

Browse files
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -16,7 +16,26 @@ from langchain_google_genai import ChatGoogleGenerativeAI
16
  from langchain_core.messages import HumanMessage
17
  from langchain_google_genai import GoogleGenerativeAIEmbeddings
18
 
19
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  # Initialize the text splitter
22
  text_splitter = RecursiveCharacterTextSplitter(
 
16
  from langchain_core.messages import HumanMessage
17
  from langchain_google_genai import GoogleGenerativeAIEmbeddings
18
 
19
+ # Load proxy credentials from Hugging Face Secrets
20
+ PROXY_USER = os.environ.get("PROXY_USER")
21
+ PROXY_PASS = os.environ.get("PROXY_PASS")
22
+ PROXY_HOST = os.environ.get("PROXY_HOST")
23
+ PROXY_PORT = os.environ.get("PROXY_PORT")
24
+
25
+ if not all([PROXY_USER, PROXY_PASS, PROXY_HOST, PROXY_PORT]):
26
+ raise RuntimeError("Proxy credentials not fully set in Hugging Face Secrets.")
27
+
28
+ PROXY_URL = f"http://{PROXY_USER}:{PROXY_PASS}@{PROXY_HOST}:{PROXY_PORT}"
29
+
30
+ # Create a session with proxy
31
+ proxy_session = requests.Session()
32
+ proxy_session.proxies = {
33
+ "http": PROXY_URL,
34
+ "https": PROXY_URL
35
+ }
36
+
37
+ # Patch youtube_transcript_api to use this proxy session
38
+ TranscriptListFetcher._session = proxy_session
39
 
40
  # Initialize the text splitter
41
  text_splitter = RecursiveCharacterTextSplitter(