Download app.py from immahadi/WebDAV: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/spaces/immahadi/WebDAV/resolve/main/app.py
- Command line
-
hf download hf://spaces/immahadi/WebDAV/app.py
-
curl -L -o app.py https://huggingface.co/spaces/immahadi/WebDAV/resolve/main/app.py
1.66 kB
| import gradio as gr | |
| import subprocess | |
| import os | |
| import urllib.request | |
| import time | |
| import spaces | |
| BINARY_NAME = "filebrowser" | |
| BINARY_URL = "https://github.com/gtsteffaniak/filebrowser/releases/download/v2.0.2-stable/linux-amd64-filebrowser" | |
| if not os.path.exists(BINARY_NAME): | |
| print(f"Downloading filebrowser binary from {BINARY_URL}...") | |
| req = urllib.request.Request(BINARY_URL, headers={"User-Agent": "Mozilla/5.0"}) | |
| with urllib.request.urlopen(req, timeout=60) as resp, open(BINARY_NAME, "wb") as f: | |
| f.write(resp.read()) | |
| os.chmod(BINARY_NAME, 0o755) | |
| print("Download successful.") | |
| DATA_ROOT = "/data" | |
| if not os.path.exists(DATA_ROOT): | |
| os.makedirs(DATA_ROOT, exist_ok=True) | |
| # Correct YAML format for FileBrowser Quantum v2.0.2 | |
| CONFIG_PATH = "config.yaml" | |
| with open(CONFIG_PATH, "w") as f: | |
| f.write("""server: | |
| host: "0.0.0.0" | |
| port: 8080 | |
| sources: | |
| - name: "default" | |
| path: "/data" | |
| """) | |
| print("Starting filebrowser server with config.yaml...") | |
| cmd = ["./" + BINARY_NAME, "--config", CONFIG_PATH] | |
| proc = subprocess.Popen(cmd) | |
| time.sleep(3) | |
| def dummy_gpu_fn(): | |
| """Satisfies ZeroGPU detection requirement on HF Spaces.""" | |
| return True | |
| dummy_gpu_fn() | |
| with gr.Blocks(title="FileBrowser Quantum") as demo: | |
| gr.HTML(""" | |
| <style> | |
| html, body, .gradio-container { height: 100% !important; margin: 0 !important; padding: 0 !important; } | |
| iframe { width: 100%; height: 95vh; border: none; } | |
| </style> | |
| <iframe src="http://127.0.0.1:8080" allow="fullscreen"></iframe> | |
| """) | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860) | |