Bc-AI commited on
Commit
cfc79aa
Β·
verified Β·
1 Parent(s): cee5e4a

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +23 -0
  2. app.py +28 -0
  3. requirements.txt +10 -0
Dockerfile ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Install system dependencies
6
+ RUN apt-get update && apt-get install -y \
7
+ gcc \
8
+ g++ \
9
+ && rm -rf /var/lib/apt/lists/*
10
+
11
+ # Copy requirements first to leverage Docker cache
12
+ COPY requirements.txt .
13
+ RUN pip install --no-cache-dir -r requirements.txt
14
+
15
+ # Copy application code
16
+ COPY app.py .
17
+ COPY ../shared ./shared
18
+
19
+ # Expose port for the API (will be determined by NODE_TYPE)
20
+ EXPOSE 7860
21
+
22
+ # Start the application - NODE_TYPE environment variable determines which service to run
23
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ # Main entry point for the multi-node Hugging Face API system
7
+ # This can be used to start either the head node or a worker node based on environment
8
+
9
+ def main():
10
+ node_type = os.getenv("NODE_TYPE", "head") # Default to head node
11
+
12
+ if node_type == "head":
13
+ print("πŸš€ Starting Head Node API Gateway...")
14
+ from head_node.app import app
15
+ import uvicorn
16
+ uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 7860)))
17
+ elif node_type in ["nano", "mini", "fast", "large"]:
18
+ print(f"πŸš€ Starting Worker Node for {node_type} model...")
19
+ from worker_nodes.worker_app import app
20
+ import uvicorn
21
+ uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 8000)))
22
+ else:
23
+ print(f"Unknown node type: {node_type}")
24
+ print("Use NODE_TYPE=head for head node, or NODE_TYPE=[nano|mini|fast|large] for workers")
25
+ sys.exit(1)
26
+
27
+ if __name__ == "__main__":
28
+ main()
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi==0.104.1
2
+ uvicorn==0.24.0
3
+ requests==2.31.0
4
+ pydantic==2.5.0
5
+ python-multipart==0.0.6
6
+ huggingface_hub==0.20.1
7
+ tokenizers==0.15.0
8
+ transformers==4.35.2
9
+ numpy==1.24.3
10
+ pytz==2023.3.post1