cduss commited on
Commit
07adf07
·
1 Parent(s): 595094e
Files changed (1) hide show
  1. server.py +9 -6
server.py CHANGED
@@ -1,13 +1,18 @@
 
 
 
1
  import eventlet
 
 
 
 
2
  from flask import Flask, request, send_from_directory
3
  from flask_cors import CORS
4
  from flask_socketio import SocketIO
5
 
6
- # 1) static under /static
7
  app = Flask(__name__, static_folder="static", static_url_path="/static")
8
  CORS(app)
9
-
10
- # 2) Socket.IO with wildcard CORS
11
  socketio = SocketIO(app, cors_allowed_origins="*")
12
 
13
  motor_states = {f"motor_{i}": 0.0 for i in range(6)}
@@ -40,11 +45,9 @@ def on_connect():
40
  def on_ws_control(data):
41
  motor_states.update(data)
42
  print("WS:", data)
43
- # broadcast new states back if you like
44
  socketio.emit("motor_states", motor_states)
45
 
46
 
47
  if __name__ == "__main__":
48
- # 3) run under eventlet on port 7860 (HF Spaces HTTPS)
49
- eventlet.monkey_patch()
50
  socketio.run(app, host="0.0.0.0", port=7860)
 
1
+ # server.py
2
+
3
+ # 1️⃣ Patch first, before any stdlib or 3rd-party imports
4
  import eventlet
5
+
6
+ eventlet.monkey_patch()
7
+
8
+ # 2️⃣ Now import everything else
9
  from flask import Flask, request, send_from_directory
10
  from flask_cors import CORS
11
  from flask_socketio import SocketIO
12
 
13
+ # 3️⃣ Create app as before
14
  app = Flask(__name__, static_folder="static", static_url_path="/static")
15
  CORS(app)
 
 
16
  socketio = SocketIO(app, cors_allowed_origins="*")
17
 
18
  motor_states = {f"motor_{i}": 0.0 for i in range(6)}
 
45
  def on_ws_control(data):
46
  motor_states.update(data)
47
  print("WS:", data)
 
48
  socketio.emit("motor_states", motor_states)
49
 
50
 
51
  if __name__ == "__main__":
52
+ # 4️⃣ Run under eventlet on 7860 so HF Spaces provides the TLS cert
 
53
  socketio.run(app, host="0.0.0.0", port=7860)