Spaces:
Runtime error
Runtime error
Create app.py
Browse files12345678910111213141516171819202122232425262728293031323334from flask import Flaskfrom flask_socketio import SocketIO, join_room, emit
# Initialize the Flask app and SocketIO instanceapp = Flask(__name__)socketio = SocketIO(app)
# Handle the connection event@socketio.on('connect')def handle_connect(): print("User connected")
# Handle room joining@socketio.on('joinRoom')def handle_join_room(room_id): join_room(room_id) print(f"User joined room: {room_id}")
# Handle receiving and broadcasting chat messages@socketio.on('chatMessage')def handle_chat_message(msg, room_id): print(f"Message received: {msg}") # Broadcast the message to everyone in the room emit('chatMessage', msg, room=room_id)
# Handle user disconnection@socketio.on('disconnect')def handle_disconnect(): print("User disconnected")
# Start the server when running this scriptif __name__ == '__main__': # Run the server on the Hugging Face Space environment socketio.run(app, host='0.0.0.0', port=5000)app.pyAdded+34