kamkol commited on
Commit
e9def50
·
1 Parent(s): 29628d2

Removed unnecessary dependencies

Browse files
Files changed (3) hide show
  1. Dockerfile +13 -24
  2. check_dependencies.py +46 -25
  3. requirements.txt +18 -12
Dockerfile CHANGED
@@ -2,40 +2,29 @@ FROM python:3.11-slim
2
 
3
  # Set Hugging Face home to persistent storage
4
  ENV HF_HOME=/data/.huggingface
5
-
6
- # Create expected directory structure
7
- RUN mkdir -p /data/processed_data
8
-
9
  WORKDIR /app
10
 
11
- # Install system dependencies for scipy
12
- RUN apt-get update && apt-get install -y \
13
- build-essential \
 
 
14
  && rm -rf /var/lib/apt/lists/*
15
 
16
- # Copy requirements first for better caching
17
  COPY requirements.txt .
18
  RUN pip install --no-cache-dir -r requirements.txt
19
 
20
- # Explicitly install sentence-transformers (sometimes needed for HF Spaces)
21
- RUN pip install --no-cache-dir sentence-transformers==2.3.0
22
 
23
- # Create necessary directories
24
- RUN mkdir -p data/processed_data
25
-
26
- # Copy the application code
27
  COPY app/ ./app/
28
- COPY data/processed_data/chunks.pkl ./data/processed_data/
29
- COPY data/processed_data/embedded_docs.pkl ./data/processed_data/
30
  COPY check_dependencies.py ./
31
 
32
- # Enable more verbose logging
33
- ENV PYTHONUNBUFFERED=1
34
-
35
- # Run a quick check to verify dependencies are installed correctly
36
- RUN python check_dependencies.py || echo "Dependency check completed with warnings"
37
 
38
- # Set the entry point to run the Streamlit app
39
- # Use debug.py to troubleshoot if the main app fails
40
  EXPOSE 8501
41
- CMD ["streamlit", "run", "app/app.py", "--server.address=0.0.0.0", "--server.port=8501", "--logger.level=debug"]
 
2
 
3
  # Set Hugging Face home to persistent storage
4
  ENV HF_HOME=/data/.huggingface
 
 
 
 
5
  WORKDIR /app
6
 
7
+ # Install system dependencies first
8
+ RUN apt-get update && apt-get install -y --no-install-recommends \
9
+ gcc \
10
+ python3-dev \
11
+ libgomp1 \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # Copy and install Python dependencies
15
  COPY requirements.txt .
16
  RUN pip install --no-cache-dir -r requirements.txt
17
 
18
+ # Create directory structure for Hugging Face Spaces
19
+ RUN mkdir -p /data/processed_data && chmod -R 777 /data
20
 
21
+ # Copy application code
 
 
 
22
  COPY app/ ./app/
 
 
23
  COPY check_dependencies.py ./
24
 
25
+ # Verify dependencies
26
+ RUN python check_dependencies.py
 
 
 
27
 
28
+ # Expose and run
 
29
  EXPOSE 8501
30
+ CMD ["streamlit", "run", "app/app.py", "--server.address=0.0.0.0", "--server.port=8501"]
check_dependencies.py CHANGED
@@ -1,7 +1,9 @@
1
  #!/usr/bin/env python3
 
2
  """
3
  Script to check installed dependencies for troubleshooting
4
  """
 
5
  import sys
6
  import pkg_resources
7
  import importlib
@@ -11,7 +13,8 @@ def check_imports():
11
  """Check if critical imports work"""
12
  success = True
13
  critical_imports = [
14
- "sentence_transformers",
 
15
  "streamlit",
16
  "langchain_core",
17
  "langchain_openai",
@@ -19,7 +22,7 @@ def check_imports():
19
  "numpy",
20
  "scipy"
21
  ]
22
-
23
  print("\n=== Import Checks ===")
24
  for module_name in critical_imports:
25
  try:
@@ -31,21 +34,35 @@ def check_imports():
31
  print(f"✗ {module_name}: FAILED - {str(e)}")
32
  return success
33
 
34
- def check_sentence_transformer():
35
- """Check if SentenceTransformer works properly"""
36
- print("\n=== SentenceTransformer Check ===")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  try:
38
- from sentence_transformers import SentenceTransformer
39
- print(f"SentenceTransformer version: {SentenceTransformer.__version__}")
40
-
41
- # Try loading a lightweight default model to see if it works
42
- print("Testing with a default model...")
43
- model = SentenceTransformer('all-MiniLM-L6-v2')
44
- test_embedding = model.encode("Test sentence to check if embeddings work")
45
- print(f"✓ Successfully created embedding with shape: {test_embedding.shape}")
46
  return True
47
  except Exception as e:
48
- print(f"✗ SentenceTransformer test failed: {str(e)}")
49
  return False
50
 
51
  def print_system_info():
@@ -59,37 +76,41 @@ def main():
59
  """Main function to run checks"""
60
  print("=== Dependency Check ===")
61
  print_system_info()
62
-
63
  # Get all installed packages
64
  installed_packages = {pkg.key: pkg.version for pkg in pkg_resources.working_set}
65
-
66
  # Check for specific dependencies
67
  key_packages = [
68
- "sentence-transformers",
69
- "streamlit",
70
- "langchain-core",
 
71
  "langchain-openai",
72
  "langgraph",
73
  "numpy",
74
  "scipy"
75
  ]
76
-
77
  print("\n=== Package Versions ===")
78
  for pkg in key_packages:
79
  version = installed_packages.get(pkg, "Not installed")
80
  print(f"{pkg}: {version}")
81
-
82
  # Test imports
83
  imports_ok = check_imports()
84
 
85
- # Test SentenceTransformer
86
- st_ok = check_sentence_transformer()
87
 
 
 
 
88
  # Final result
89
- if imports_ok and st_ok:
90
  print("\n✓ All critical checks passed")
91
  else:
92
  print("\n✗ Some checks failed, see details above")
93
 
94
  if __name__ == "__main__":
95
- main()
 
1
  #!/usr/bin/env python3
2
+
3
  """
4
  Script to check installed dependencies for troubleshooting
5
  """
6
+
7
  import sys
8
  import pkg_resources
9
  import importlib
 
13
  """Check if critical imports work"""
14
  success = True
15
  critical_imports = [
16
+ "transformers",
17
+ "torch",
18
  "streamlit",
19
  "langchain_core",
20
  "langchain_openai",
 
22
  "numpy",
23
  "scipy"
24
  ]
25
+
26
  print("\n=== Import Checks ===")
27
  for module_name in critical_imports:
28
  try:
 
34
  print(f"✗ {module_name}: FAILED - {str(e)}")
35
  return success
36
 
37
+ def check_transformers_model():
38
+ """Check if transformers can load your fine-tuned model"""
39
+ print("\n=== Transformers Model Check ===")
40
+ try:
41
+ from transformers import AutoModel, AutoTokenizer
42
+ model_name = "kamkol/ab_testing_finetuned_arctic_ft-36dfff22-0696-40d2-b3bf-268fe2ff2aec"
43
+ print(f"Testing loading model: {model_name}")
44
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
45
+ model = AutoModel.from_pretrained(model_name)
46
+ inputs = tokenizer("Test sentence", return_tensors="pt")
47
+ with torch.no_grad():
48
+ outputs = model(**inputs)
49
+ print("✓ Successfully loaded model and ran forward pass")
50
+ return True
51
+ except Exception as e:
52
+ print(f"✗ Transformers model test failed: {str(e)}")
53
+ return False
54
+
55
+ def check_langchain_components():
56
+ """Check critical LangChain components"""
57
+ print("\n=== LangChain Check ===")
58
  try:
59
+ from langchain_core.messages import HumanMessage
60
+ from langchain_core.prompts import ChatPromptTemplate
61
+ from langgraph.graph import StateGraph
62
+ print("✓ LangChain core components imported successfully")
 
 
 
 
63
  return True
64
  except Exception as e:
65
+ print(f"✗ LangChain check failed: {str(e)}")
66
  return False
67
 
68
  def print_system_info():
 
76
  """Main function to run checks"""
77
  print("=== Dependency Check ===")
78
  print_system_info()
79
+
80
  # Get all installed packages
81
  installed_packages = {pkg.key: pkg.version for pkg in pkg_resources.working_set}
82
+
83
  # Check for specific dependencies
84
  key_packages = [
85
+ "transformers",
86
+ "torch",
87
+ "streamlit",
88
+ "langchain-core",
89
  "langchain-openai",
90
  "langgraph",
91
  "numpy",
92
  "scipy"
93
  ]
94
+
95
  print("\n=== Package Versions ===")
96
  for pkg in key_packages:
97
  version = installed_packages.get(pkg, "Not installed")
98
  print(f"{pkg}: {version}")
99
+
100
  # Test imports
101
  imports_ok = check_imports()
102
 
103
+ # Test transformers model
104
+ tf_ok = check_transformers_model()
105
 
106
+ # Test LangChain
107
+ lc_ok = check_langchain_components()
108
+
109
  # Final result
110
+ if imports_ok and tf_ok and lc_ok:
111
  print("\n✓ All critical checks passed")
112
  else:
113
  print("\n✗ Some checks failed, see details above")
114
 
115
  if __name__ == "__main__":
116
+ main()
requirements.txt CHANGED
@@ -1,15 +1,21 @@
 
 
 
 
 
 
 
 
 
1
  langchain-community==0.3.14
2
  langchain-openai==0.2.14
3
- langchain-qdrant>=0.2.0
4
  langgraph==0.2.61
5
- numpy<2.0.0,>=1.22.4
6
- unstructured>=0.14.8
7
- arxiv>=1.4.0
8
- streamlit>=1.38.0
9
- tiktoken>=0.6.0
10
- python-dotenv>=1.0.1
11
- qdrant-client>=1.7.0
12
- scipy>=1.10.0
13
- sentence-transformers==2.3.0
14
- transformers>=4.51.3
15
- torch>=2.0.1
 
1
+ # Core dependencies
2
+ transformers==4.51.3
3
+ torch==2.3.0+cpu
4
+ numpy==1.26.4
5
+ scipy==1.13.0
6
+ streamlit==1.36.0
7
+
8
+ # LangChain ecosystem
9
+ langchain-core==0.2.4
10
  langchain-community==0.3.14
11
  langchain-openai==0.2.14
 
12
  langgraph==0.2.61
13
+
14
+ # Hugging Face integration
15
+ huggingface-hub==0.23.2
16
+
17
+ # Additional utilities
18
+ python-dotenv==1.0.1
19
+ arxiv==1.4.9
20
+ tiktoken==0.7.0
21
+ unstructured==0.14.8