Perilon commited on
Commit
c23fdff
·
1 Parent(s): ef0931a
Files changed (4) hide show
  1. .hf-space +14 -0
  2. Dockerfile +3 -1
  3. flask_app.py +31 -2
  4. requirements.txt +1 -0
.hf-space ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ build_docker: true
2
+ config:
3
+ app_port: 7860
4
+ env:
5
+ - SECRET_KEY=f7290fc27f11dbf14be6cd348638ad62
6
+ - DEBUG=True
7
+ - PORT=7860
8
+ - SPACE_ID=true
9
+ - BYPASS_AUTH=true
10
+ resources:
11
+ cpu: 1
12
+ memory: 1
13
+ gpu: null
14
+ restarts: true
Dockerfile CHANGED
@@ -18,6 +18,8 @@ ENV PORT=7860
18
  ENV SPACE_ID="true"
19
  # Add explicit environment variable to enable authentication bypass for troubleshooting
20
  ENV BYPASS_AUTH="true"
 
 
21
 
22
  # Create necessary directories
23
  RUN mkdir -p data/videos data/annotations data/temp data/word_timestamps data/alignments data/transcripts
@@ -26,4 +28,4 @@ RUN mkdir -p data/videos data/annotations data/temp data/word_timestamps data/al
26
  EXPOSE 7860
27
 
28
  # Run with gunicorn for better stability
29
- CMD ["python", "flask_app.py"]
 
18
  ENV SPACE_ID="true"
19
  # Add explicit environment variable to enable authentication bypass for troubleshooting
20
  ENV BYPASS_AUTH="true"
21
+ ENV SECRET_KEY="f7290fc27f11dbf14be6cd348638ad62"
22
+ ENV DEBUG="True"
23
 
24
  # Create necessary directories
25
  RUN mkdir -p data/videos data/annotations data/temp data/word_timestamps data/alignments data/transcripts
 
28
  EXPOSE 7860
29
 
30
  # Run with gunicorn for better stability
31
+ CMD exec gunicorn --bind :7860 --workers 1 --threads 2 --timeout 600 "flask_app:app"
flask_app.py CHANGED
@@ -177,12 +177,29 @@ def auth_callback():
177
  return render_template('error.html', message="Authentication failed. No username provided.")
178
  return redirect(url_for('login'))
179
 
 
180
  @app.route('/health')
181
  def health_check():
182
  """Health check endpoint for container verification."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  return jsonify({
184
  "status": "healthy",
185
- "environment": os.environ.get('FLASK_ENV', 'production'),
 
186
  "is_hf_space": is_hf_space,
187
  "bypass_auth": bypass_auth,
188
  "directories": {
@@ -197,6 +214,9 @@ def auth():
197
  """This route handles HF authentication."""
198
  logger.info(f"Auth route called. Headers: {dict(request.headers)}")
199
 
 
 
 
200
  # If bypass is enabled, authenticate immediately
201
  if bypass_auth:
202
  logger.info("Auth bypass enabled, setting default user")
@@ -225,12 +245,21 @@ def auth():
225
  def check_auth():
226
  """Check authentication before processing requests."""
227
  # Skip authentication for certain routes and static files
228
- if request.path in ['/login', '/logout', '/auth', '/auth/callback', '/debug'] or request.path.startswith('/static/'):
229
  return
230
 
 
 
 
231
  # Log all request paths to help troubleshoot
232
  logger.debug(f"Request path: {request.path}, User in session: {'user' in session}")
233
 
 
 
 
 
 
 
234
  if is_hf_space:
235
  # Check for HF username header
236
  username = request.headers.get('X-Spaces-Username')
 
177
  return render_template('error.html', message="Authentication failed. No username provided.")
178
  return redirect(url_for('login'))
179
 
180
+ # Replace the health check route with this improved version
181
  @app.route('/health')
182
  def health_check():
183
  """Health check endpoint for container verification."""
184
+ # Log environment variables for debugging
185
+ env_vars = {
186
+ "FLASK_ENV": os.environ.get('FLASK_ENV', 'production'),
187
+ "DEBUG": os.environ.get('DEBUG', 'Not set'),
188
+ "SPACE_ID": os.environ.get('SPACE_ID', 'Not set'),
189
+ "BYPASS_AUTH": os.environ.get('BYPASS_AUTH', 'Not set'),
190
+ "SECRET_KEY": os.environ.get('SECRET_KEY', 'Not set')[:5] + '...' if os.environ.get('SECRET_KEY') else 'Not set'
191
+ }
192
+
193
+ logger.info(f"Health check called. Environment: {env_vars}")
194
+
195
+ # Get session information for debugging
196
+ session_info = dict(session) if session else None
197
+ session_keys = list(session.keys()) if session else []
198
+
199
  return jsonify({
200
  "status": "healthy",
201
+ "environment": env_vars,
202
+ "session_keys": session_keys,
203
  "is_hf_space": is_hf_space,
204
  "bypass_auth": bypass_auth,
205
  "directories": {
 
214
  """This route handles HF authentication."""
215
  logger.info(f"Auth route called. Headers: {dict(request.headers)}")
216
 
217
+ # Force bypass auth to be true for debugging
218
+ bypass_auth = True
219
+
220
  # If bypass is enabled, authenticate immediately
221
  if bypass_auth:
222
  logger.info("Auth bypass enabled, setting default user")
 
245
  def check_auth():
246
  """Check authentication before processing requests."""
247
  # Skip authentication for certain routes and static files
248
+ if request.path in ['/login', '/logout', '/auth', '/auth/callback', '/debug', '/health'] or request.path.startswith('/static/'):
249
  return
250
 
251
+ # Force bypass auth to be true for debugging
252
+ bypass_auth = True
253
+
254
  # Log all request paths to help troubleshoot
255
  logger.debug(f"Request path: {request.path}, User in session: {'user' in session}")
256
 
257
+ if bypass_auth:
258
+ # Set default user for bypass mode if not already set
259
+ if 'user' not in session:
260
+ session['user'] = {'name': 'Perilon', 'is_hf': True}
261
+ return
262
+
263
  if is_hf_space:
264
  # Check for HF username header
265
  username = request.headers.get('X-Spaces-Username')
requirements.txt CHANGED
@@ -4,3 +4,4 @@ requests
4
  boto3
5
  authlib
6
  ffmpeg-python
 
 
4
  boto3
5
  authlib
6
  ffmpeg-python
7
+ gunicorn