LeonardoMdSA commited on
Commit
bb37020
·
1 Parent(s): bc72e65

readme and push

Browse files
Files changed (5) hide show
  1. Dockerfile +28 -20
  2. README.md +0 -2
  3. app/config.py +18 -2
  4. docker-compose.yml +13 -32
  5. start.sh +0 -15
Dockerfile CHANGED
@@ -1,7 +1,8 @@
1
- # Base Image
2
  FROM python:3.11-slim
3
 
4
- # System Dependencies
 
 
5
  RUN apt-get update && \
6
  apt-get install -y --no-install-recommends \
7
  build-essential \
@@ -9,36 +10,43 @@ RUN apt-get update && \
9
  curl \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
- # Working Directory
13
  WORKDIR /app
14
 
15
- # Copy Repo Files
16
- COPY . /app
17
-
18
- # Python Dependencies
19
  RUN python -m pip install --upgrade pip setuptools wheel
 
20
  RUN pip install --no-cache-dir \
21
  fastapi \
22
  uvicorn[standard] \
23
- streamlit \
24
  pydantic-settings \
25
  pydantic \
26
  requests \
27
- scikit-learn \
28
- transformers \
29
- python-multipart
 
 
 
 
 
 
30
 
31
- # Environment Variables
 
 
32
  ENV ENV=hf_spaces
33
  ENV DEBUG=False
34
  ENV MCP_EMBEDDED=True
35
- ENV API_HOST=127.0.0.1
36
- ENV API_PORT=8000
 
37
 
38
- # Expose only HF port (Streamlit)
39
- EXPOSE 8501
40
 
41
- # Entrypoint
42
- COPY start.sh /app/start.sh
43
- RUN chmod +x /app/start.sh
44
- ENTRYPOINT ["/app/start.sh"]
 
 
1
  FROM python:3.11-slim
2
 
3
+ # -------------------------
4
+ # System dependencies
5
+ # -------------------------
6
  RUN apt-get update && \
7
  apt-get install -y --no-install-recommends \
8
  build-essential \
 
10
  curl \
11
  && rm -rf /var/lib/apt/lists/*
12
 
 
13
  WORKDIR /app
14
 
15
+ # -------------------------
16
+ # Python dependencies
17
+ # -------------------------
 
18
  RUN python -m pip install --upgrade pip setuptools wheel
19
+
20
  RUN pip install --no-cache-dir \
21
  fastapi \
22
  uvicorn[standard] \
 
23
  pydantic-settings \
24
  pydantic \
25
  requests \
26
+ scikit-learn==1.8.0 \
27
+ python-multipart \
28
+ joblib \
29
+ jinja2
30
+
31
+ # -------------------------
32
+ # Copy application
33
+ # -------------------------
34
+ COPY . /app
35
 
36
+ # -------------------------
37
+ # Environment (HF Spaces)
38
+ # -------------------------
39
  ENV ENV=hf_spaces
40
  ENV DEBUG=False
41
  ENV MCP_EMBEDDED=True
42
+ ENV ENABLE_ABSTENTION=False
43
+ ENV API_HOST=0.0.0.0
44
+ ENV API_PORT=7860
45
 
46
+ # HF default port
47
+ EXPOSE 7860
48
 
49
+ # -------------------------
50
+ # Run FastAPI directly
51
+ # -------------------------
52
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -15,8 +15,6 @@ venv\Scripts\activate
15
 
16
  uvicorn app.main:app --reload --host 127.0.0.1 --port 8000
17
 
18
- streamlit run ui/streamlit_app.py --server.port 8501 --server.address 127.0.0.1
19
-
20
  ### Tests
21
 
22
  pytest -v
 
15
 
16
  uvicorn app.main:app --reload --host 127.0.0.1 --port 8000
17
 
 
 
18
  ### Tests
19
 
20
  pytest -v
app/config.py CHANGED
@@ -1,8 +1,10 @@
 
1
  from functools import lru_cache
2
  from pathlib import Path
3
- from pydantic_settings import BaseSettings # updated for Pydantic v2
4
  from pydantic import Field
5
 
 
6
 
7
  class Settings(BaseSettings):
8
  """
@@ -81,7 +83,21 @@ def get_settings() -> Settings:
81
  Ensures consistent config across the app.
82
  """
83
  settings = Settings()
84
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  # Ensure required directories exist (safe for HF Spaces)
86
  settings.LOG_DIR.mkdir(parents=True, exist_ok=True)
87
  settings.MODEL_DIR.mkdir(parents=True, exist_ok=True)
 
1
+ import logging
2
  from functools import lru_cache
3
  from pathlib import Path
4
+ from pydantic_settings import BaseSettings
5
  from pydantic import Field
6
 
7
+ logger = logging.getLogger(__name__)
8
 
9
  class Settings(BaseSettings):
10
  """
 
83
  Ensures consistent config across the app.
84
  """
85
  settings = Settings()
86
+
87
+ # HARD SAFETY GUARD FOR HF SPACES
88
+ # -------------------------
89
+ if settings.ENV == "hf_spaces":
90
+ settings.MCP_EMBEDDED = True
91
+ settings.MCP_FAIL_FAST = False
92
+ settings.ENABLE_ABSTENTION = False
93
+ logger.info(
94
+ "HF Spaces detected — forcing embedded MCP mode",
95
+ extra={
96
+ "env": settings.ENV,
97
+ "mcp_embedded": settings.MCP_EMBEDDED,
98
+ "abstention": settings.ENABLE_ABSTENTION,
99
+ },
100
+ )
101
  # Ensure required directories exist (safe for HF Spaces)
102
  settings.LOG_DIR.mkdir(parents=True, exist_ok=True)
103
  settings.MODEL_DIR.mkdir(parents=True, exist_ok=True)
docker-compose.yml CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  version: "3.9"
2
 
3
  services:
@@ -7,7 +13,7 @@ services:
7
  backend:
8
  build:
9
  context: .
10
- dockerfile: Dockerfile # Root-level Dockerfile
11
  container_name: nlp_backend
12
  command: uvicorn app.main:app --host 0.0.0.0 --port 8000
13
  ports:
@@ -18,34 +24,17 @@ services:
18
  - ./logs:/app/logs
19
  - ./data:/app/data
20
  environment:
21
- - ENV=local
22
- - DEBUG=True
23
- - MCP_EMBEDDED=False
24
- - MCP_TAXONOMY_URL=http://taxonomy_server:7001
25
- - MCP_POLICY_URL=http://policy_server:7002
26
- - MCP_HISTORY_URL=http://history_server:7003
27
  depends_on:
28
  - taxonomy_server
29
  - policy_server
30
  - history_server
31
 
32
- # -------------------------
33
- # Streamlit Frontend
34
- # -------------------------
35
- frontend:
36
- image: python:3.11-slim
37
- container_name: nlp_frontend
38
- working_dir: /app
39
- command: streamlit run ui/streamlit_app.py --server.port 8501 --server.address 0.0.0.0
40
- ports:
41
- - "8501:8501"
42
- volumes:
43
- - ./:/app
44
- depends_on:
45
- - backend
46
- environment:
47
- - ENV=local
48
-
49
  # -------------------------
50
  # MCP Servers
51
  # -------------------------
@@ -78,11 +67,3 @@ services:
78
  - "7003:7003"
79
  volumes:
80
  - ./mcp_servers/history_server/data:/app/data
81
-
82
- # -------------------------
83
- # Shared Volumes (optional)
84
- # -------------------------
85
- volumes:
86
- models:
87
- data:
88
- logs:
 
1
+ # =====================================================
2
+ # LOCAL DEVELOPMENT ONLY
3
+ # Not used or supported by Hugging Face Spaces
4
+ # Provides distributed MCP servers for local testing
5
+ # =====================================================
6
+
7
  version: "3.9"
8
 
9
  services:
 
13
  backend:
14
  build:
15
  context: .
16
+ dockerfile: Dockerfile
17
  container_name: nlp_backend
18
  command: uvicorn app.main:app --host 0.0.0.0 --port 8000
19
  ports:
 
24
  - ./logs:/app/logs
25
  - ./data:/app/data
26
  environment:
27
+ ENV: local
28
+ DEBUG: "true"
29
+ MCP_EMBEDDED: "false"
30
+ MCP_DISTRIBUTED_TAXONOMY_URL: http://taxonomy_server:7001
31
+ MCP_DISTRIBUTED_POLICY_URL: http://policy_server:7002
32
+ MCP_DISTRIBUTED_HISTORY_URL: http://history_server:7003
33
  depends_on:
34
  - taxonomy_server
35
  - policy_server
36
  - history_server
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  # -------------------------
39
  # MCP Servers
40
  # -------------------------
 
67
  - "7003:7003"
68
  volumes:
69
  - ./mcp_servers/history_server/data:/app/data
 
 
 
 
 
 
 
 
start.sh DELETED
@@ -1,15 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- # HF provides $PORT for the UI
5
- PORT=${PORT:-8501}
6
-
7
- echo "Starting FastAPI server in background..."
8
- uvicorn app.main:app \
9
- --host 127.0.0.1 \
10
- --port 8000 &
11
-
12
- echo "Starting Streamlit UI..."
13
- streamlit run ui/streamlit_app.py \
14
- --server.port $PORT \
15
- --server.address 0.0.0.0