ndc8 commited on
Commit
4f67c26
Β·
1 Parent(s): 557b035
Files changed (6) hide show
  1. .dockerignore +26 -0
  2. Dockerfile +31 -0
  3. README.md +1 -2
  4. app.py +10 -0
  5. space.yaml +0 -3
  6. test_app_structure.py +39 -0
.dockerignore ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Ignore unnecessary files for Docker build
2
+ __pycache__/
3
+ *.pyc
4
+ *.pyo
5
+ *.pyd
6
+ .Python
7
+ .env
8
+ .venv
9
+ env/
10
+ venv/
11
+ .git/
12
+ .gitignore
13
+ *.md
14
+ !README.md
15
+ .DS_Store
16
+ *.log
17
+ training_runs/
18
+ .github/
19
+ sample_data/
20
+ scripts/
21
+ test_*.py
22
+ debug_*.py
23
+ usage_examples.py
24
+ *.yaml
25
+ *.yml
26
+ !requirements.txt
Dockerfile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Python 3.10 slim image
2
+ FROM python:3.10-slim
3
+
4
+ # Set up a new user named "user" with user ID 1000 (required by HF Spaces)
5
+ RUN useradd -m -u 1000 user
6
+
7
+ # Switch to the "user" user
8
+ USER user
9
+
10
+ # Set home to the user's home directory
11
+ ENV HOME=/home/user \
12
+ PATH=/home/user/.local/bin:$PATH \
13
+ HF_HOME=/tmp/.cache/huggingface \
14
+ TRANSFORMERS_NO_ADVISORY_WARNINGS=1
15
+
16
+ # Set the working directory to the user's home directory
17
+ WORKDIR $HOME/app
18
+
19
+ # Copy requirements and install dependencies
20
+ COPY --chown=user requirements.txt .
21
+ RUN pip install --no-cache-dir --upgrade pip && \
22
+ pip install --no-cache-dir -r requirements.txt
23
+
24
+ # Copy the application code
25
+ COPY --chown=user . .
26
+
27
+ # Expose port 7860 (HF Spaces default)
28
+ EXPOSE 7860
29
+
30
+ # Command to run the application
31
+ CMD ["python", "-m", "uvicorn", "backend_service:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -4,8 +4,7 @@ emoji: "πŸ€–"
4
  colorFrom: "blue"
5
  colorTo: "green"
6
  sdk: "docker"
7
- sdk_version: "1.0"
8
- app_file: backend_service.py
9
  pinned: false
10
  ---
11
 
 
4
  colorFrom: "blue"
5
  colorTo: "green"
6
  sdk: "docker"
7
+ app_port: 7860
 
8
  pinned: false
9
  ---
10
 
app.py CHANGED
@@ -1 +1,11 @@
 
 
 
 
 
 
1
  from backend_service import app
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Entry point for Hugging Face Spaces
4
+ This file imports and runs the FastAPI application from backend_service
5
+ """
6
+
7
  from backend_service import app
8
+
9
+ if __name__ == "__main__":
10
+ import uvicorn
11
+ uvicorn.run(app, host="0.0.0.0", port=7860)
space.yaml DELETED
@@ -1,3 +0,0 @@
1
- sdk: docker
2
- python_version: 3.10
3
- entrypoint: python -m uvicorn backend_service:app --host 0.0.0.0 --port $PORT
 
 
 
 
test_app_structure.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Test script to verify the FastAPI app can be imported and started
4
+ """
5
+
6
+ import sys
7
+ import os
8
+
9
+ # Add current directory to path
10
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
11
+
12
+ try:
13
+ # Test imports
14
+ print("Testing imports...")
15
+ from backend_service import app
16
+ print("βœ… Successfully imported FastAPI app from backend_service")
17
+
18
+ # Test app type
19
+ from fastapi import FastAPI
20
+ if isinstance(app, FastAPI):
21
+ print("βœ… App is a valid FastAPI instance")
22
+ else:
23
+ print("❌ App is not a FastAPI instance")
24
+ sys.exit(1)
25
+
26
+ # Test app attributes
27
+ print(f"βœ… App title: {app.title}")
28
+ print(f"βœ… App version: {app.version}")
29
+
30
+ print("\nπŸŽ‰ All tests passed! The app is ready for Hugging Face Spaces")
31
+
32
+ except ImportError as e:
33
+ print(f"❌ Import error: {e}")
34
+ print("This is expected if you don't have all dependencies installed locally.")
35
+ print("The Hugging Face Space will install them from requirements.txt")
36
+
37
+ except Exception as e:
38
+ print(f"❌ Unexpected error: {e}")
39
+ sys.exit(1)