liaoch commited on
Commit
5b05b42
·
1 Parent(s): dd5c2cf

Fix app_port for Hugging Face Spaces: Change to 7860 and update all related configurations

Browse files
Files changed (3) hide show
  1. Dockerfile +5 -5
  2. README.md +4 -4
  3. app.py +2 -2
Dockerfile CHANGED
@@ -83,15 +83,15 @@ RUN $HOME/app/venv/bin/pip install --no-cache-dir -r $HOME/app/requirements.txt
83
  # Copy the rest of the application code into the container with proper ownership
84
  COPY --chown=user . $HOME/app
85
 
86
- # Make port 80 available to the world outside this container (required for Hugging Face Spaces)
87
- EXPOSE 80
88
 
89
  # Define environment variables
90
  # IMPORTANT: Set a strong FLASK_SECRET_KEY when running the container!
91
  # Using a placeholder here for demonstration.
92
  ENV FLASK_APP=app.py
93
  ENV FLASK_RUN_HOST=0.0.0.0
94
- ENV FLASK_RUN_PORT=80
95
  ENV FLASK_SECRET_KEY="replace_this_in_docker_run_with_a_real_secret"
96
  # Add venv's bin to the PATH for subsequent commands (like CMD)
97
  ENV PATH="$HOME/app/venv/bin:$PATH"
@@ -102,7 +102,7 @@ ENTRYPOINT []
102
  # Run the application using Gunicorn when the container launches
103
  # Use the full path to gunicorn within the virtual environment
104
  # Bind to 0.0.0.0 to accept connections from outside the container
105
- # Use port 80 (required for Hugging Face Spaces)
106
  # The number of workers (e.g., --workers 3) can be adjusted based on server resources
107
  # Use JSON form with the absolute path to gunicorn in the venv to avoid PATH issues
108
- CMD ["gunicorn", "--workers", "3", "--bind", "0.0.0.0:80", "--timeout", "60", "app:app"]
 
83
  # Copy the rest of the application code into the container with proper ownership
84
  COPY --chown=user . $HOME/app
85
 
86
+ # Make port 7860 available to the world outside this container (required for Hugging Face Spaces)
87
+ EXPOSE 7860
88
 
89
  # Define environment variables
90
  # IMPORTANT: Set a strong FLASK_SECRET_KEY when running the container!
91
  # Using a placeholder here for demonstration.
92
  ENV FLASK_APP=app.py
93
  ENV FLASK_RUN_HOST=0.0.0.0
94
+ ENV FLASK_RUN_PORT=7860
95
  ENV FLASK_SECRET_KEY="replace_this_in_docker_run_with_a_real_secret"
96
  # Add venv's bin to the PATH for subsequent commands (like CMD)
97
  ENV PATH="$HOME/app/venv/bin:$PATH"
 
102
  # Run the application using Gunicorn when the container launches
103
  # Use the full path to gunicorn within the virtual environment
104
  # Bind to 0.0.0.0 to accept connections from outside the container
105
+ # Use port 7860 (required for Hugging Face Spaces)
106
  # The number of workers (e.g., --workers 3) can be adjusted based on server resources
107
  # Use JSON form with the absolute path to gunicorn in the venv to avoid PATH issues
108
+ CMD ["gunicorn", "--workers", "3", "--bind", "0.0.0.0:7860", "--timeout", "60", "app:app"]
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🔥
4
  colorFrom: purple
5
  colorTo: red
6
  sdk: docker
7
- app_port: 80
8
  pinned: false
9
  license: mit
10
  short_description: mermaid-rendering docker version
@@ -70,15 +70,15 @@ This is the recommended way to run the application, as it bundles all dependenci
70
  ```bash
71
  # Replace 'YOUR_GENERATED_SECRET_KEY' with the key from step 2.
72
  # -d: Run in detached mode (background)
73
- # -p 80:80: Map port 80 on the host to port 80 in the container
74
  # --name mermaid-app: Assign a name to the container for easier management
75
  # -e FLASK_SECRET_KEY=...: Set the environment variable inside the container
76
  # mermaid-renderer-app: The name of the image to run
77
- docker run -d -p 80:80 --name mermaid-app \
78
  -e FLASK_SECRET_KEY='YOUR_GENERATED_SECRET_KEY' \
79
  mermaid-renderer-app
80
  ```
81
- *Note:* If port 80 is already in use on your host, choose a different host port (e.g., `-p 8080:80`).
82
 
83
  5. **Access the Application:** Open your web browser and navigate to `http://localhost` (or `http://your_server_ip` if deploying remotely). If you used a different host port, include it (e.g., `http://localhost:8080`).
84
 
 
4
  colorFrom: purple
5
  colorTo: red
6
  sdk: docker
7
+ app_port: 7860
8
  pinned: false
9
  license: mit
10
  short_description: mermaid-rendering docker version
 
70
  ```bash
71
  # Replace 'YOUR_GENERATED_SECRET_KEY' with the key from step 2.
72
  # -d: Run in detached mode (background)
73
+ # -p 7860:7860: Map port 7860 on the host to port 7860 in the container
74
  # --name mermaid-app: Assign a name to the container for easier management
75
  # -e FLASK_SECRET_KEY=...: Set the environment variable inside the container
76
  # mermaid-renderer-app: The name of the image to run
77
+ docker run -d -p 7860:7860 --name mermaid-app \
78
  -e FLASK_SECRET_KEY='YOUR_GENERATED_SECRET_KEY' \
79
  mermaid-renderer-app
80
  ```
81
+ *Note:* If port 7860 is already in use on your host, choose a different host port (e.g., `-p 8080:7860`).
82
 
83
  5. **Access the Application:** Open your web browser and navigate to `http://localhost` (or `http://your_server_ip` if deploying remotely). If you used a different host port, include it (e.g., `http://localhost:8080`).
84
 
app.py CHANGED
@@ -184,5 +184,5 @@ if __name__ == '__main__':
184
  # Use 0.0.0.0 to be accessible on the network
185
  # Set debug=False for production-like testing, or True for development features
186
  is_debug = os.environ.get('FLASK_DEBUG', 'false').lower() == 'true'
187
- # Use port 80 for Hugging Face Spaces compatibility
188
- app.run(debug=is_debug, host='0.0.0.0', port=int(os.environ.get('PORT', 80)))
 
184
  # Use 0.0.0.0 to be accessible on the network
185
  # Set debug=False for production-like testing, or True for development features
186
  is_debug = os.environ.get('FLASK_DEBUG', 'false').lower() == 'true'
187
+ # Use port 7860 for Hugging Face Spaces compatibility
188
+ app.run(debug=is_debug, host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))