Zelyanoth commited on
Commit
be73adb
Β·
1 Parent(s): 4eeabd7
HUGGING_FACE_DEPLOYMENT.md DELETED
@@ -1,197 +0,0 @@
1
- # Hosting Lin on Hugging Face Spaces
2
-
3
- This guide explains how to deploy your Lin application (Vite + React + Tailwind frontend with Flask backend) on Hugging Face Spaces.
4
-
5
- ## Project Structure
6
-
7
- Hugging Face Spaces requires both frontend and backend to run in the same environment. Organize your project as follows:
8
-
9
- ```
10
- Lin/
11
- β”œβ”€β”€ backend/
12
- β”‚ β”œβ”€β”€ app.py
13
- β”‚ β”œβ”€β”€ requirements.txt
14
- β”‚ └── ... (other backend files)
15
- β”œβ”€β”€ frontend/
16
- β”‚ β”œβ”€β”€ package.json
17
- β”‚ β”œβ”€β”€ vite.config.js
18
- β”‚ └── ... (other frontend files)
19
- β”œβ”€β”€ app.py # Main entry point for Flask
20
- β”œβ”€β”€ requirements.txt # Python dependencies
21
- β”œβ”€β”€ runtime.txt # Python version (optional)
22
- β”œβ”€β”€ README.md # Project documentation
23
- └── Dockerfile # Docker configuration (optional)
24
- ```
25
-
26
- ## Prerequisites
27
-
28
- 1. Build your Vite frontend (Hugging Face Spaces cannot run Vite dev server)
29
- 2. Configure Flask to serve both API endpoints and static frontend files
30
- 3. Set up proper environment variables for production
31
-
32
- ## Step-by-Step Deployment
33
-
34
- ### 1. Build the Frontend
35
-
36
- Before deployment, you need to build your React frontend:
37
-
38
- ```bash
39
- cd frontend
40
- npm install
41
- npm run build
42
- ```
43
-
44
- This creates a `dist/` folder with static assets that Flask can serve.
45
-
46
- ### 2. Configure Flask to Serve Frontend
47
-
48
- Your Flask app is already configured to serve the frontend. The `backend/app.py` file includes routes to serve static files from the `frontend/dist` directory.
49
-
50
- ### 3. Update Environment Variables
51
-
52
- Update your `.env` files for production:
53
-
54
- **frontend/.env.production:**
55
- ```bash
56
- VITE_API_URL=https://zelyanoth-lin-cbfcff2.hf.space
57
- VITE_NODE_ENV=production
58
- ```
59
-
60
- **backend/.env:**
61
- ```bash
62
- # LinkedIn OAuth configuration
63
- REDIRECT_URL=https://zelyanoth-lin-cbfcff2.hf.space/auth/callback
64
-
65
- # Other configurations...
66
- ```
67
-
68
- Don't forget to update your LinkedIn App settings in the LinkedIn Developer Console to use this redirect URL.
69
-
70
- ### 4. Root requirements.txt
71
-
72
- Create a `requirements.txt` file at the project root with all necessary Python dependencies:
73
-
74
- ```
75
- flask
76
- flask-jwt-extended
77
- supabase
78
- python-dotenv
79
- celery
80
- redis
81
- # Add other backend dependencies
82
- ```
83
-
84
- ### 5. Runtime Configuration (Optional)
85
-
86
- Create a `runtime.txt` file to specify the Python version:
87
-
88
- ```
89
- python-3.10
90
- ```
91
-
92
- ### 6. Hugging Face Metadata
93
-
94
- Add Hugging Face metadata to your `README.md`:
95
-
96
- ```markdown
97
- ---
98
- title: Lin - LinkedIn Community Manager
99
- sdk: docker
100
- app_file: app.py
101
- license: mit
102
- ---
103
- ```
104
-
105
- ### 7. Docker Configuration (Optional)
106
-
107
- If you want more control over the deployment environment, create a `Dockerfile`:
108
-
109
- ```dockerfile
110
- FROM python:3.10
111
-
112
- WORKDIR /app
113
-
114
- # Install Node.js for frontend build
115
- RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
116
- RUN apt-get update && apt-get install -y nodejs
117
-
118
- # Copy and install Python dependencies
119
- COPY requirements.txt .
120
- RUN pip install -r requirements.txt
121
-
122
- # Copy package files for frontend
123
- COPY frontend/package*.json ./frontend/
124
- # Install frontend dependencies
125
- RUN cd frontend && npm install
126
-
127
- # Copy all files
128
- COPY . .
129
-
130
- # Build frontend
131
- RUN cd frontend && npm run build
132
-
133
- # Expose port
134
- EXPOSE 7860
135
-
136
- # Run the application
137
- CMD ["python", "app.py"]
138
- ```
139
-
140
- ### 8. Deploy to Hugging Face Spaces
141
-
142
- 1. Create a new Space on Hugging Face:
143
- - Go to https://huggingface.co/new-space
144
- - Choose "Python (Docker)" as the SDK
145
- - Give your Space a name
146
-
147
- 2. Push your code via Git:
148
- ```bash
149
- git init
150
- git remote add origin https://huggingface.co/spaces/<username>/<space-name>
151
- git add .
152
- git commit -m "Deploy to Hugging Face Spaces"
153
- git push origin main
154
- ```
155
-
156
- ## How It Works
157
-
158
- 1. Hugging Face installs Python and Node.js dependencies
159
- 2. During the build process, it runs `npm run build` in the frontend directory
160
- 3. It installs Python dependencies from `requirements.txt`
161
- 4. It runs `python app.py`
162
- 5. Flask serves both:
163
- - Your API endpoints (e.g., `/api/*`)
164
- - Your compiled React frontend (static files from `frontend/dist`)
165
-
166
- ## Scheduler (Celery) Considerations
167
-
168
- Your application uses Celery for scheduling tasks. On Hugging Face Spaces:
169
-
170
- 1. **Celery Worker and Beat** can run in the same container as your Flask app
171
- 2. **Redis** is used as the broker and result backend
172
- 3. **Task Persistence** is handled through the database, not just the Celery schedule file
173
-
174
- The scheduler will work, but you should be aware that:
175
- - Hugging Face Spaces might put your app to sleep after periods of inactivity
176
- - When the app wakes up, the Celery processes will restart
177
- - Your schedules are stored in the database, so they will be reloaded when the app restarts
178
-
179
- ## Access Your Application
180
-
181
- After deployment, your app will be available at:
182
- `https://zelyanoth-lin-cbfcff2.hf.space`
183
-
184
- ## Troubleshooting
185
-
186
- 1. **Frontend not loading**: Ensure you've run `npm run build` and committed the `dist/` folder
187
- 2. **API calls failing**: Check that your `VITE_API_URL` points to the correct Space URL
188
- 3. **OAuth issues**: Verify that your redirect URL in both the `.env` file and LinkedIn Developer Console match your Space URL
189
- 4. **Build errors**: Check the build logs in your Space's "Files" tab for detailed error messages
190
- 5. **Scheduler not working**: Check that Redis is available and that Celery processes are running
191
-
192
- ## Additional Notes
193
-
194
- - Hugging Face Spaces has resource limitations, so optimize your application accordingly
195
- - For production use with significant traffic, consider using a more robust hosting solution
196
- - Regularly update your dependencies to ensure security patches
197
- - Monitor your Space's logs for any runtime errors
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
  title: Lin - LinkedIn Community Manager
3
  sdk: docker
4
- app_file: app.py
5
  license: mit
6
  ---
7
 
 
1
  ---
2
  title: Lin - LinkedIn Community Manager
3
  sdk: docker
4
+ app_file: start_app.py
5
  license: mit
6
  ---
7
 
backend/start_celery.py CHANGED
@@ -42,7 +42,7 @@ def start_worker():
42
  sys.executable, "-m", "celery",
43
  "-A", "celery_config:celery_app",
44
  "worker",
45
- "--loglevel=info",
46
  "--pool=solo",
47
  "--max-tasks-per-child=100",
48
  "--events" # Enable task events for monitoring
@@ -68,7 +68,7 @@ def start_beat():
68
  sys.executable, "-m", "celery",
69
  "-A", "celery_config:celery_app",
70
  "beat",
71
- "--loglevel=info",
72
  "--schedule=/tmp/celerybeat-schedule" # Specify writable location for schedule file
73
  ]
74
 
 
42
  sys.executable, "-m", "celery",
43
  "-A", "celery_config:celery_app",
44
  "worker",
45
+ "--loglevel=debug",
46
  "--pool=solo",
47
  "--max-tasks-per-child=100",
48
  "--events" # Enable task events for monitoring
 
68
  sys.executable, "-m", "celery",
69
  "-A", "celery_config:celery_app",
70
  "beat",
71
+ "--loglevel=debug",
72
  "--schedule=/tmp/celerybeat-schedule" # Specify writable location for schedule file
73
  ]
74
 
start_app.py CHANGED
@@ -43,7 +43,7 @@ def start_celery_components():
43
  sys.executable, "-m", "celery",
44
  "-A", "celery_config:celery_app",
45
  "worker",
46
- "--loglevel=info",
47
  "--pool=solo",
48
  "--max-tasks-per-child=100",
49
  "--events" # Enable task events for monitoring
@@ -54,7 +54,7 @@ def start_celery_components():
54
  sys.executable, "-m", "celery",
55
  "-A", "celery_config:celery_app",
56
  "beat",
57
- "--loglevel=info",
58
  "--schedule=/tmp/celerybeat-schedule" # Specify writable location for schedule file
59
  ]
60
 
 
43
  sys.executable, "-m", "celery",
44
  "-A", "celery_config:celery_app",
45
  "worker",
46
+ "--loglevel=debug",
47
  "--pool=solo",
48
  "--max-tasks-per-child=100",
49
  "--events" # Enable task events for monitoring
 
54
  sys.executable, "-m", "celery",
55
  "-A", "celery_config:celery_app",
56
  "beat",
57
+ "--loglevel=debug",
58
  "--schedule=/tmp/celerybeat-schedule" # Specify writable location for schedule file
59
  ]
60