File size: 1,927 Bytes
e3e5444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
"""
Flask Frontend Application for Autonomous AI Data Analyst Agent.
Serves the UI only; the browser calls the FastAPI backend directly.
"""
import os
import logging
from flask import Flask, render_template, jsonify

app = Flask(__name__, template_folder="templates", static_folder="static")

# Configuration
BACKEND_URL = os.getenv("BACKEND_URL", "http://127.0.0.1:8000")
REQUIRE_API_KEY = os.getenv("REQUIRE_API_KEY", "false").lower() == "true"
APP_VERSION = os.getenv("APP_VERSION", "0.1.0")

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


# ============================================================================
# FRONTEND ROUTES
# ============================================================================

@app.route("/")
def index():
    """Serve main dashboard page."""
    return render_template(
        "index.html",
        app_version=APP_VERSION,
        require_api_key=REQUIRE_API_KEY,
        backend_url=BACKEND_URL
    )


@app.route("/health")
def health():
    """Health check endpoint."""
    return jsonify({
        "status": "ok",
        "version": APP_VERSION,
        "frontend": "flask"
    })


# ============================================================================
# UTILITY ROUTES
# ============================================================================

@app.route("/api/config", methods=["GET"])
def get_config():
    """Get frontend configuration."""
    return jsonify({
        "backend_url": BACKEND_URL,
        "require_api_key": REQUIRE_API_KEY,
        "app_version": APP_VERSION
    })


if __name__ == "__main__":
    debug = os.getenv("FLASK_DEBUG", "false").lower() == "true"
    port = int(os.getenv("FLASK_PORT", "5000"))
    host = os.getenv("FLASK_HOST", "0.0.0.0")

    logger.info(f"Starting Flask frontend on {host}:{port}")
    logger.info(f"Backend URL: {BACKEND_URL}")

    app.run(host=host, port=port, debug=debug)