File size: 3,347 Bytes
1ab614e
df11666
1ab614e
df11666
 
 
 
 
39c7ec8
 
 
1ab614e
df11666
 
1ab614e
 
 
 
 
 
df11666
 
1ab614e
d82b005
 
 
2248b40
d82b005
 
 
 
2248b40
1ab614e
 
 
7a5c5fe
1ab614e
df11666
1ab614e
98056e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194f181
 
98056e5
194f181
98056e5
194f181
98056e5
194f181
98056e5
 
 
 
194f181
 
98056e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df11666
 
 
 
1ab614e
34d1933
 
 
 
df11666
 
 
 
 
 
86916f6
511df0a
df11666
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""
Hugging Face Spaces entry point for DemoPrep.

Secrets to set in HF Spaces → Settings → Repository Secrets:
  SUPABASE_URL          Supabase project URL
  SUPABASE_ANON_KEY     Supabase anonymous key
  OPENAI_API_KEY        OpenAI API key (primary LLM)
  GOOGLE_API_KEY        Google API key (optional, for Gemini models)
  SLACK_BOT_TOKEN       Slack bot token for outbound deployment notifications
  SLACK_DEPLOYMENT_CHANNEL_ID
                        Slack channel ID for deployment notifications

All other credentials (Snowflake, ThoughtSpot) are stored in Supabase
admin settings and loaded at runtime — no extra HF secrets needed.
"""

import os
import sys
from pathlib import Path

# Ensure repo root is on the path
sys.path.insert(0, str(Path(__file__).parent))

# Patch gradio_client bug: schema traversal crashes when schema is a bool
# (happens when a component has additionalProperties: true in its JSON schema).
# Both get_type() and _json_schema_to_python_type() must guard against non-dict input.
import gradio_client.utils as _gcu
_orig_get_type = _gcu.get_type
_gcu.get_type = lambda schema: _orig_get_type(schema) if isinstance(schema, dict) else "any"
_orig_j2p = _gcu._json_schema_to_python_type
_gcu._json_schema_to_python_type = lambda schema, defs=None: "any" if not isinstance(schema, dict) else _orig_j2p(schema, defs)

os.makedirs("results", exist_ok=True)
os.makedirs("demo_logs", exist_ok=True)

from demoprep_app.controllers.chat import authenticate_user, create_chat_interface

app = create_chat_interface()


def _git_commit() -> str:
    try:
        import subprocess

        return subprocess.check_output(
            ["git", "rev-parse", "--short", "HEAD"],
            cwd=Path(__file__).parent,
            text=True,
            stderr=subprocess.DEVNULL,
        ).strip()
    except Exception:
        return os.getenv("GIT_COMMIT", "unknown")


def build_info():
    pipeline_ok = False
    pipeline_error = ""
    try:
        from demoprep_app.pipeline.build_demo import build_demo

        pipeline_ok = callable(build_demo)
    except Exception as exc:
        pipeline_error = str(exc)

    return {
        "app": "demoprep",
        "commit": _git_commit(),
        "pipeline_ok": pipeline_ok,
        "pipeline_import_error": pipeline_error,
    }


import gradio.routes as _gr_routes
_orig_create_app = _gr_routes.App.create_app


def _create_app_with_build_info(blocks, app_kwargs=None, auth_dependency=None):
    server_app = _orig_create_app(
        blocks,
        app_kwargs=app_kwargs,
        auth_dependency=auth_dependency,
    )
    if not getattr(server_app.state, "_demoprep_build_info_route", False):
        server_app.add_api_route(
            "/build-info",
            build_info,
            methods=["GET"],
            include_in_schema=False,
        )
        server_app.state._demoprep_build_info_route = True
    return server_app


_gr_routes.App.create_app = staticmethod(_create_app_with_build_info)

app.queue(
    default_concurrency_limit=10,
    api_open=False,
)

# Bypass Gradio localhost accessibility check (httpx 0.28 compatibility)
import gradio.networking as _gn
_gn.url_ok = lambda url: True

app.launch(
    server_name="0.0.0.0",
    server_port=7860,
    share=False,
    inbrowser=False,
    auth=authenticate_user,

    show_api=False,
)