Skip to main content

HealSpace — Guardian AI for Hugging Face Spaces

Project description

HealSpace

PyPI License Python

HealSpace is a guardian AI package for Hugging Face Spaces.

It automatically detects backend errors, attempts auto-fixes, and injects a live healing panel into your Gradio app — all in one line of code.


✨ Features

  • Auto-detects 9 common Space error types: missing deps, port conflicts, GPU OOM, Gradio mismatches, disk quota, startup timeouts, syntax errors, auth errors, and generic RuntimeErrors
  • Auto-fixes what it can: installs missing packages at runtime, clears CUDA cache, frees locked ports
  • Gradio UI panel — paste any traceback and get a structured report + fix steps
  • "Error this Space" demo button — trigger a live healing demo in your app
  • Background monitor — watches stderr continuously and heals without intervention
  • Lineage seal🛡️ Protected by HealSpace footer on every protected app

📦 Installation

Add to your Space's requirements.txt:

healspace

Or install locally:

pip install healspace

🚀 Quickstart

Minimal — one line in app.py

import gradio as gr
from healspace import heal

with gr.Blocks() as demo:
    gr.Markdown("# My Space")
    # ... your UI ...

heal(demo)          # inject guardian panel + start monitor
demo.launch()

That's it. HealSpace will:

  1. Add a collapsible 🛡️ HealSpace accordion to your app
  2. Start a background monitor watching for errors
  3. Stamp the lineage seal in the footer

Diagnose a log snippet

from healspace import diagnose

log = """
Traceback (most recent call last):
  File "app.py", line 3, in <module>
    import mylib
ModuleNotFoundError: No module named 'mylib'
"""

reports = diagnose(log)
for r in reports:
    print(r)

Output:

[HealSpace] ERROR: Missing dependency: mylib
  The package 'mylib' is not installed in this Space.
  Suggested fixes:
    1. Add 'mylib' to your requirements.txt
    2. Trigger a factory reboot via Space Settings → Factory reboot
    3. If it's a system package, add it to packages.txt instead

Auto-fix

from healspace import diagnose, fix

reports = diagnose(open("space.log").read())
for r in reports:
    fix(r)       # attempts auto-fix; prints steps if no auto-fix available

Full control

from healspace import HealSpace

hs = HealSpace(auto_fix=True, verbose=True)

# Start background stderr monitor
hs.watch()

# Inject UI into your Gradio app
hs.protect(demo)

demo.launch()

🩺 Detected Error Types

Error type Trigger Auto-fix
missing_dep ModuleNotFoundError ✅ pip-installs at runtime
port_conflict Address already in use ✅ frees port 7860
gpu_oom CUDA out of memory ✅ clears CUDA cache
gradio_mismatch Gradio AttributeError / bad import ❌ suggests pinning version
disk_full No space left on device ❌ suggests cache cleanup
startup_timeout Space timeout errors ❌ suggests lazy loading
syntax_error SyntaxError / IndentationError ❌ points to exact file
auth_error 401/403 / RepositoryNotFoundError ❌ guides to HF_TOKEN secret
runtime_error Generic RuntimeError ❌ suggests restart + debug

🗂 Project Structure

healspace/
├── healspace/
│   ├── __init__.py   ← public API: heal, diagnose, fix, HealSpace
│   ├── core.py       ← HealSpace class + auto-fixers + Gradio injection
│   └── errors.py     ← KnownError pattern registry + ErrorReport dataclass
└── pyproject.toml

📋 Changelog

v0.2.0

  • Complete rewrite — v0.1.0 was an empty package (no source files)
  • HealSpace class with diagnose, fix, heal, protect, watch
  • 9 known error patterns with structured ErrorReport output
  • Auto-fixers for missing deps, port conflicts, GPU OOM
  • Gradio UI panel injection with "Diagnose & Heal" + "Error this Space" buttons
  • Background stderr monitor thread
  • heal(), diagnose(), fix() convenience functions at module level

v0.1.0

  • Initial (incomplete) release

📄 License

Apache 2.0 — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

healspace-0.3.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

healspace-0.3.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file healspace-0.3.0.tar.gz.

File metadata

  • Download URL: healspace-0.3.0.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for healspace-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e7d417d15499321e1d35b615c9cd12c106bc1bc0ceb1704eac985838dccca126
MD5 932a87ba610e2fabb59142fe286ecc8b
BLAKE2b-256 7e176cd52936f2c986c56de37fd04d14e37fc95e4016f8722aea10c023045ff4

See more details on using hashes here.

File details

Details for the file healspace-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: healspace-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for healspace-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4508692484a7b6a91875c5d4f767c0b5ddba5a0613a2e5c2ed45c3eb5620f1c
MD5 934a4c4854d58f22476b01e82775b76d
BLAKE2b-256 51307c67c315c5c8a856f684ed5a0692dbb26c35c4e3ebcd56cf7ae2829d760f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page