Download app.py from Vvbbnnn/logupdate: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/Vvbbnnn/logupdate/resolve/main/app.py
- Command line
-
hf download hf://spaces/Vvbbnnn/logupdate/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Vvbbnnn/logupdate/resolve/main/app.py
1.05 kB
| from flask import Flask, request, jsonify | |
| from flask import Response | |
| import time | |
| app = Flask(__name__) | |
| logs = [] | |
| def index(): | |
| return """ | |
| <h2>Live Logs</h2> | |
| <pre id="logs"></pre> | |
| <script> | |
| var evtSource = new EventSource("/stream"); | |
| evtSource.onmessage = function(e) { | |
| document.getElementById("logs").textContent += e.data + "\\n"; | |
| }; | |
| </script> | |
| """ | |
| def stream(): | |
| def event_stream(): | |
| last = 0 | |
| while True: | |
| if len(logs) > last: | |
| yield f"data: {logs[-1]}\\n\\n" | |
| last = len(logs) | |
| time.sleep(0.5) | |
| return Response(event_stream(), mimetype="text/event-stream") | |
| def log(): | |
| data = request.json | |
| if not data or "log" not in data: | |
| return jsonify({"error": "no log"}), 400 | |
| logs.append(data["log"]) | |
| print("LOG RECEIVED:", data["log"]) # 🔥 IMPORTANT DEBUG | |
| return jsonify({"status": "ok"}) | |
| app.run(host="0.0.0.0", port=7860) |