Spaces:
Runtime error
Runtime error
Download app.py from Ashraf-CK/TransienTalk-socket: direct link, hf CLI and curl.
- Browser
- Download file 966 Bytes
-
https://huggingface.co/spaces/Ashraf-CK/TransienTalk-socket/resolve/main/app.py
- Command line
-
hf download hf://spaces/Ashraf-CK/TransienTalk-socket/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Ashraf-CK/TransienTalk-socket/resolve/main/app.py
966 Bytes
| from flask import Flask | |
| from flask_socketio import SocketIO, join_room, emit | |
| # Initialize the Flask app and SocketIO instance | |
| app = Flask(__name__) | |
| socketio = SocketIO(app) | |
| # Handle the connection event | |
| def handle_connect(): | |
| print("User connected") | |
| # Handle room joining | |
| def handle_join_room(room_id): | |
| join_room(room_id) | |
| print(f"User joined room: {room_id}") | |
| # Handle receiving and broadcasting chat messages | |
| 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 | |
| def handle_disconnect(): | |
| print("User disconnected") | |
| # Start the server when running this script | |
| if __name__ == '__main__': | |
| # Run the server on the Hugging Face Space environment | |
| socketio.run(app, host='0.0.0.0', port=5000) | |