| """ |
| Flask application entrypoint. |
| |
| At this stage of the build (Layer 1), only the database and authentication |
| are wired up so this layer can be tested in isolation. Chat/RAG/agent |
| routes will be added in later layers. |
| """ |
| |
|
|
|
|
| import os |
| import threading |
|
|
| |
| |
| os.environ["NO_PROXY"] = "127.0.0.1,localhost," + os.environ.get("NO_PROXY", "") |
| os.environ["no_proxy"] = os.environ["NO_PROXY"] |
|
|
| |
| |
| |
| |
| |
| |
| |
| import gradio_client.utils as _gc_utils |
|
|
| _orig_get_type = _gc_utils.get_type |
| _orig_json_schema_to_python_type = _gc_utils._json_schema_to_python_type |
|
|
| import spaces |
|
|
| @spaces.GPU(duration=1) |
| def _warmup(): |
| return True |
|
|
| |
|
|
| def _safe_get_type(schema): |
| if isinstance(schema, bool): |
| return "Any" |
| return _orig_get_type(schema) |
|
|
|
|
| def _safe_json_schema_to_python_type(schema, defs=None): |
| if isinstance(schema, bool): |
| return "Any" |
| return _orig_json_schema_to_python_type(schema, defs) |
|
|
|
|
| _gc_utils.get_type = _safe_get_type |
| _gc_utils._json_schema_to_python_type = _safe_json_schema_to_python_type |
| |
|
|
| from flask import Flask |
|
|
| import config |
| from auth.db import init_db |
| from auth.routes import auth_bp |
| from chat_routes import chat_bp |
| from ui.layout import build_ui |
|
|
|
|
| def create_app(): |
| app = Flask(__name__) |
|
|
| app.config["SECRET_KEY"] = config.SECRET_KEY |
| app.config["SQLALCHEMY_DATABASE_URI"] = config.SQLALCHEMY_DATABASE_URI |
| app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = config.SQLALCHEMY_TRACK_MODIFICATIONS |
|
|
| init_db(app) |
|
|
| app.register_blueprint(auth_bp) |
| app.register_blueprint(chat_bp) |
|
|
| @app.route("/health") |
| def health(): |
| return {"status": "ok"} |
|
|
| return app |
|
|
|
|
| if __name__ == "__main__": |
| flask_app = create_app() |
|
|
| |
| api_thread = threading.Thread( |
| target=lambda: flask_app.run(port=5000, debug=False, use_reloader=False), |
| daemon=True, |
| ) |
| api_thread.start() |
|
|
| |
| |
| demo = build_ui(flask_app) |
| demo.queue().launch( |
| server_name="0.0.0.0", |
| server_port=7860, |
| show_api=False, |
| inbrowser=False, |
| ) |