Ashmit003 commited on
Commit
c8711ff
Β·
1 Parent(s): 9d5563a

Edited Docker file again

Browse files
Files changed (3) hide show
  1. rag_pipeline/llms.py +31 -24
  2. requirements.txt +3 -0
  3. streamlit_app.py +4 -0
rag_pipeline/llms.py CHANGED
@@ -1,47 +1,54 @@
1
- #LLLM.py
2
 
 
 
3
  from langchain.embeddings import CacheBackedEmbeddings
4
  from langchain.storage import LocalFileStore
5
  from langchain_groq import ChatGroq
6
- from langchain_openai import OpenAIEmbeddings
7
- from langchain_community.embeddings import HuggingFaceEmbeddings
8
-
9
-
10
- import sys
11
- import os
12
-
13
 
14
- # Path setup
 
 
15
  current_dir = os.path.dirname(os.path.abspath(__file__))
16
  parent_dir = os.path.abspath(os.path.join(current_dir, '..'))
17
  if parent_dir not in sys.path:
18
  sys.path.insert(0, parent_dir)
19
 
 
20
 
21
- from config import set_environment
22
-
 
23
  chat_model = ChatGroq(
24
- model = "deepseek-r1-distill-llama-70b",
25
- #model = "llama-3.3-70b-versatile",
26
- temperature = 0,
27
- max_tokens = 1024,
28
- timeout = None,
29
- max_retries = 2,
30
  )
31
 
 
 
 
32
 
33
- # Step 1: Set up local byte store for caching
 
 
 
 
34
  store = LocalFileStore("./cache/")
35
 
36
- # Step 2: Initialize HuggingFace embeddings
37
  underlying_embeddings = HuggingFaceEmbeddings(
38
- model_name="intfloat/e5-base", # High-quality embedding model
39
- cache_folder="./embeddings_cache" # Optional: local cache for model files
 
40
  )
41
 
42
- # Step 3: Wrap with cache-backed embeddings
43
  Embeddings = CacheBackedEmbeddings.from_bytes_store(
44
  underlying_embeddings,
45
  store,
46
- namespace="intfloat/e5-base" # Explicit namespace for cache isolation
47
- )
 
1
+ # llms.py
2
 
3
+ import os
4
+ import sys
5
  from langchain.embeddings import CacheBackedEmbeddings
6
  from langchain.storage import LocalFileStore
7
  from langchain_groq import ChatGroq
8
+ from langchain_huggingface import HuggingFaceEmbeddings # Updated import
 
 
 
 
 
 
9
 
10
+ # ─────────────────────────────────────────────
11
+ # πŸ”§ Path Setup for Modular Imports
12
+ # ─────────────────────────────────────────────
13
  current_dir = os.path.dirname(os.path.abspath(__file__))
14
  parent_dir = os.path.abspath(os.path.join(current_dir, '..'))
15
  if parent_dir not in sys.path:
16
  sys.path.insert(0, parent_dir)
17
 
18
+ from config import set_environment # Ensure env vars are loaded early
19
 
20
+ # ─────────────────────────────────────────────
21
+ # πŸ’¬ Chat Model Initialization
22
+ # ─────────────────────────────────────────────
23
  chat_model = ChatGroq(
24
+ model="deepseek-r1-distill-llama-70b",
25
+ temperature=0,
26
+ max_tokens=1024,
27
+ timeout=None,
28
+ max_retries=2,
 
29
  )
30
 
31
+ # ─────────────────────────────────────────────
32
+ # 🧠 Embedding Setup with Caching
33
+ # ─────────────────────────────────────────────
34
 
35
+ # Ensure Hugging Face cache is writable (esp. on Spaces)
36
+ os.environ["HF_HOME"] = "/tmp/huggingface"
37
+ os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface"
38
+
39
+ # Local byte store for embedding cache
40
  store = LocalFileStore("./cache/")
41
 
42
+ # Updated embedding class from langchain-huggingface
43
  underlying_embeddings = HuggingFaceEmbeddings(
44
+ model_name="BAAI/bge-small-en-v1.5", # More stable than intfloat/e5-base
45
+ model_kwargs={"device": "cpu"},
46
+ encode_kwargs={"normalize_embeddings": True}
47
  )
48
 
49
+ # Wrap with LangChain's cache-backed embedding layer
50
  Embeddings = CacheBackedEmbeddings.from_bytes_store(
51
  underlying_embeddings,
52
  store,
53
+ namespace="bge-small-en-v1.5"
54
+ )
requirements.txt CHANGED
@@ -33,4 +33,7 @@ python-docx
33
  unstructured
34
  beautifulsoup4
35
  html2text
 
 
 
36
 
 
33
  unstructured
34
  beautifulsoup4
35
  html2text
36
+ langchain-huggingface>=0.3.1
37
+ sentence-transformers>=2.6.1
38
+ transformers>=4.40.0
39
 
streamlit_app.py CHANGED
@@ -5,6 +5,10 @@ import os
5
  current_dir = os.path.dirname(os.path.abspath(__file__))
6
  sys.path.append(current_dir)
7
 
 
 
 
 
8
  # Import and run the actual Streamlit app
9
  from rag_pipeline import rag_streamlit_app
10
 
 
5
  current_dir = os.path.dirname(os.path.abspath(__file__))
6
  sys.path.append(current_dir)
7
 
8
+ import torch
9
+ torch.classes.__path__ = [] # Suppress PyTorch class instantiation error
10
+
11
+
12
  # Import and run the actual Streamlit app
13
  from rag_pipeline import rag_streamlit_app
14