Spaces:
Paused
Paused
Download app.py from smodusermc/nyarch-vm: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/spaces/smodusermc/nyarch-vm/resolve/main/app.py
- Command line
-
hf download hf://spaces/smodusermc/nyarch-vm/app.py
-
curl -L -o app.py https://huggingface.co/spaces/smodusermc/nyarch-vm/resolve/main/app.py
1.63 kB
| from flask import Flask, render_template, request, jsonify, send_from_directory | |
| from flask_cors import CORS | |
| import os | |
| app = Flask(__name__) | |
| CORS(app) | |
| ISO_PATH = "/home/user/iso/nyarch.iso" | |
| ISO_DIR = "/home/user/iso" | |
| NOVNC_PATH = "/usr/share/novnc" | |
| def index(): | |
| return send_from_directory(NOVNC_PATH, "vnc.html") | |
| def upload_chunk(): | |
| chunk = request.files.get("chunk") | |
| chunk_number = int(request.form.get("chunkNumber", 0)) | |
| total_chunks = int(request.form.get("totalChunks", 1)) | |
| if chunk: | |
| os.makedirs(ISO_DIR, exist_ok=True) | |
| mode = "wb" if chunk_number == 0 else "ab" | |
| with open(ISO_PATH, mode) as f: | |
| f.write(chunk.read()) | |
| if chunk_number + 1 >= total_chunks: | |
| return jsonify({"status": "complete"}) | |
| progress = int((chunk_number + 1) / total_chunks * 100) | |
| return jsonify({"status": "uploading", "progress": progress}) | |
| return jsonify({"status": "error"}), 400 | |
| def status(): | |
| iso_exists = os.path.exists(ISO_PATH) | |
| iso_size = os.path.getsize(ISO_PATH) if iso_exists else 0 | |
| return jsonify( | |
| { | |
| "iso_exists": iso_exists, | |
| "iso_size": iso_size, | |
| "iso_size_mb": round(iso_size / 1024 / 1024, 2), | |
| } | |
| ) | |
| def serve_novnc(filename="vnc.html"): | |
| return send_from_directory(NOVNC_PATH, filename) | |
| if __name__ == "__main__": | |
| os.makedirs(ISO_DIR, exist_ok=True) | |
| app.run(host="0.0.0.0", port=7860, debug=False, threaded=True) | |