AntDX316
commited on
Commit
·
d6b652b
1
Parent(s):
51bd74e
updated
Browse files- Dockerfile +15 -20
- README.md +6 -6
- app.py +34 -0
Dockerfile
CHANGED
@@ -1,25 +1,20 @@
|
|
1 |
-
FROM
|
2 |
|
3 |
-
|
4 |
-
RUN rm -f /etc/nginx/nginx.conf && rm -f /etc/nginx/conf.d/default.conf
|
5 |
|
6 |
-
# Copy
|
7 |
-
COPY
|
|
|
|
|
|
|
8 |
|
9 |
-
#
|
10 |
-
RUN mkdir -p /tmp/client_temp \
|
11 |
-
/tmp/proxy_temp \
|
12 |
-
/tmp/fastcgi_temp \
|
13 |
-
/tmp/scgi_temp \
|
14 |
-
/tmp/uwsgi_temp
|
15 |
-
|
16 |
-
# Copy the application files to the nginx html directory
|
17 |
-
COPY index.html /usr/share/nginx/html/
|
18 |
-
COPY styles.css /usr/share/nginx/html/
|
19 |
-
COPY script.js /usr/share/nginx/html/
|
20 |
-
|
21 |
-
# Hugging Face Spaces typically expects the app on port 8080
|
22 |
EXPOSE 8080
|
23 |
|
24 |
-
#
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10-slim
|
2 |
|
3 |
+
WORKDIR /app
|
|
|
4 |
|
5 |
+
# Copy application files
|
6 |
+
COPY index.html /app/
|
7 |
+
COPY styles.css /app/
|
8 |
+
COPY script.js /app/
|
9 |
+
COPY app.py /app/
|
10 |
|
11 |
+
# Expose port 8080 which is what HF Spaces expects
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
EXPOSE 8080
|
13 |
|
14 |
+
# Set environment variables for HF Spaces
|
15 |
+
ENV PORT=8080
|
16 |
+
ENV PYTHONUNBUFFERED=1
|
17 |
+
ENV DOCKER_CONTAINER=true
|
18 |
+
|
19 |
+
# Run the Python application
|
20 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
@@ -81,13 +81,13 @@ This application can also be run using Docker, which ensures consistent behavior
|
|
81 |
|
82 |
### Deploying to Hugging Face Spaces
|
83 |
|
84 |
-
This application is compatible with Hugging Face Spaces Docker deployments. The Docker configuration has been specifically
|
85 |
|
86 |
-
1. **
|
87 |
-
2. **
|
88 |
-
3. **
|
89 |
-
4. **
|
90 |
-
5. **
|
91 |
|
92 |
To deploy to Hugging Face Spaces:
|
93 |
|
|
|
81 |
|
82 |
### Deploying to Hugging Face Spaces
|
83 |
|
84 |
+
This application is compatible with Hugging Face Spaces Docker deployments. The Docker configuration has been specifically designed for the Hugging Face Spaces environment:
|
85 |
|
86 |
+
1. **Simple Python HTTP Server**: Instead of using Nginx (which has permission issues on Spaces), we use Python's built-in HTTP server
|
87 |
+
2. **Port 8080**: The web server listens on port 8080 (the default port expected by Hugging Face Spaces)
|
88 |
+
3. **Python-based Entry Point**: Using app.py as the main entry point improves compatibility with Hugging Face's environment
|
89 |
+
4. **Minimal Dependencies**: No complex web server configurations required, making deployment more reliable
|
90 |
+
5. **Environment Variable Integration**: The app detects when it's running in a Docker container on Hugging Face
|
91 |
|
92 |
To deploy to Hugging Face Spaces:
|
93 |
|
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import http.server
|
3 |
+
import socketserver
|
4 |
+
from urllib.parse import urlparse
|
5 |
+
|
6 |
+
# This file is used by Hugging Face Spaces to properly identify the app
|
7 |
+
|
8 |
+
# The port that the app will be served on
|
9 |
+
PORT = int(os.environ.get("PORT", 8080))
|
10 |
+
|
11 |
+
# Use the directory containing index.html
|
12 |
+
web_dir = os.path.dirname(os.path.abspath(__file__))
|
13 |
+
os.chdir(web_dir)
|
14 |
+
|
15 |
+
# Create a simple HTTP request handler
|
16 |
+
class SimpleHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
|
17 |
+
def log_request(self, code='-', size='-'):
|
18 |
+
# Override to reduce logging noise
|
19 |
+
if isinstance(code, str):
|
20 |
+
pass
|
21 |
+
elif code >= 400:
|
22 |
+
print(f"HTTP Error {code}: {self.requestline}")
|
23 |
+
else:
|
24 |
+
pass # Don't log successful requests
|
25 |
+
|
26 |
+
# Print startup message
|
27 |
+
print(f"Starting Battle Simulator on port {PORT}")
|
28 |
+
print(f"Serving from directory: {web_dir}")
|
29 |
+
print("App can be accessed at the 'App' tab in the Space UI")
|
30 |
+
|
31 |
+
# Start the server
|
32 |
+
with socketserver.TCPServer(("", PORT), SimpleHTTPRequestHandler) as httpd:
|
33 |
+
print(f"Serving HTTP on 0.0.0.0 port {PORT}")
|
34 |
+
httpd.serve_forever()
|