File size: 1,530 Bytes
298d6c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/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__)

@app.route('/health')
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

@app.route('/')
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)