Spaces:
Build error
Build error
| #!/usr/bin/env python3 | |
| """ | |
| Health check endpoint for Hugging Face Spaces | |
| """ | |
| from flask import Flask, jsonify | |
| import os | |
| from pathlib import Path | |
| app = Flask(__name__) | |
| def health_check(): | |
| """Health check endpoint""" | |
| try: | |
| # Check if required directories exist | |
| required_dirs = ['scripts', 'configs', 'data'] | |
| missing_dirs = [] | |
| for dir_name in required_dirs: | |
| if not Path(dir_name).exists(): | |
| missing_dirs.append(dir_name) | |
| # Check if scripts directory has files | |
| scripts_dir = Path("scripts") | |
| script_count = len(list(scripts_dir.glob("*.py"))) if scripts_dir.exists() else 0 | |
| status = { | |
| "status": "healthy" if not missing_dirs else "degraded", | |
| "missing_directories": missing_dirs, | |
| "scripts_available": script_count, | |
| "python_version": os.sys.version, | |
| "working_directory": str(Path.cwd()) | |
| } | |
| return jsonify(status) | |
| except Exception as e: | |
| return jsonify({ | |
| "status": "unhealthy", | |
| "error": str(e) | |
| }), 500 | |
| def root(): | |
| """Root endpoint""" | |
| return jsonify({ | |
| "message": "Textilindo AI Assistant - Hugging Face Spaces", | |
| "status": "running", | |
| "endpoints": { | |
| "health": "/health", | |
| "app": "/app" | |
| } | |
| }) | |
| if __name__ == "__main__": | |
| app.run(host="0.0.0.0", port=7860, debug=False) | |