broadfield-dev commited on
Commit
6caeb35
·
verified ·
1 Parent(s): 41c2c36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -2,10 +2,15 @@ from flask import Flask, render_template, session
2
  from flask_socketio import SocketIO, emit
3
  from game import Game
4
  import uuid
 
5
 
6
  app = Flask(__name__)
7
  app.config['SECRET_KEY'] = 'your-secret-key' # Replace with a secure key
8
- socketio = SocketIO(app)
 
 
 
 
9
 
10
  # Store game instances per client session
11
  games = {}
@@ -49,4 +54,6 @@ def handle_disconnect():
49
  del games[sid] # Clean up game instance
50
 
51
  if __name__ == '__main__':
52
- socketio.run(app, host='0.0.0.0', port=7860, allow_unsafe_werkzeug=True)
 
 
 
2
  from flask_socketio import SocketIO, emit
3
  from game import Game
4
  import uuid
5
+ import os
6
 
7
  app = Flask(__name__)
8
  app.config['SECRET_KEY'] = 'your-secret-key' # Replace with a secure key
9
+
10
+ # Configure SocketIO with CORS for all origins and eventlet for Hugging Face compatibility
11
+ socketio = SocketIO(app,
12
+ cors_allowed_origins="*", # Allow all origins (or specify "https://your-space.hf.space" for security)
13
+ async_mode='eventlet') # Use eventlet for WebSocket support on Hugging Face
14
 
15
  # Store game instances per client session
16
  games = {}
 
54
  del games[sid] # Clean up game instance
55
 
56
  if __name__ == '__main__':
57
+ # Use port 7860 for Hugging Face Spaces or environment variable
58
+ port = int(os.environ.get('PORT', 7860))
59
+ socketio.run(app, debug=True, host='0.0.0.0', port=port)