from aiohttp import web import markdown import os import psutil import shutil import platform routes = web.RouteTableDef() @routes.get("/", allow_head=True) async def root_route_handler(request): # Try directory path containing this file first, then check parent directory readme_path = os.path.join(os.path.dirname(__file__), "README.md") if not os.path.exists(readme_path): readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.md") if os.path.exists(readme_path): with open(readme_path, "r", encoding="utf-8") as f: md_text = f.read() # Strip YAML frontmatter if present (Hugging Face metadata tags) if md_text.startswith("---"): parts = md_text.split("---", 2) if len(parts) >= 3: md_text = parts[2].strip() readme_html = markdown.markdown(md_text, extensions=["fenced_code", "codehilite", "tables"]) else: readme_html = "

Yugen File Store Bot Documentation

README.md not found. Create it in the root or plugins folder to display documentation here.

" # Fetch system metrics using psutil and shutil try: cpu_usage = psutil.cpu_percent() ram_usage = psutil.virtual_memory().percent total, used, free = shutil.disk_usage("/") disk_usage = round((used / total) * 100, 1) except Exception: cpu_usage = 0 ram_usage = 0 disk_usage = 0 space_id = os.environ.get("SPACE_ID", "Local Node") html_page = f""" File Store Bot - Dashboard
📂

File Store Bot

Live on: {space_id}

RUNNING
CPU Usage
{cpu_usage}%
RAM Usage
{ram_usage}%
Disk Storage
{disk_usage}%
Documentation
{readme_html}
""" return web.Response(text=html_page, content_type="text/html") app = web.Application() app.add_routes(routes) if __name__ == "__main__": web.run_app(app, port=8080)