File size: 1,467 Bytes
7800d9a
452db16
 
 
af27e39
452db16
7800d9a
 
 
8b85809
 
 
 
af27e39
 
4081e1f
af27e39
8b85809
 
 
 
 
 
 
 
b0ef78c
8b85809
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7800d9a
 
 
 
 
 
af27e39
7800d9a
 
 
 
452db16
 
 
 
 
 
 
 
 
 
 
7800d9a
 
 
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
import gradio as gr
from fastapi import FastAPI
from main import ask_tableau_agent

app = FastAPI(title="AI Analytics Agent")

def gradio_ask(question):
    return ask_tableau_agent(question)


with gr.Blocks(theme=gr.themes.Soft()) as gradio_ui:
    gr.Markdown(
        """
        # AI Analytics Agent (Conversational Analytics)
        Interact with a published dataset on Tableau **SuperStore** dataset using natural language (a LLM analytics application)

        **Examples you can try:** 
        - Top customers by profit  
        - Sales trend by category  
        """
    )

    with gr.Row():
        question_input = gr.Textbox(
            label="Your Question",
            placeholder="e.g. Show total profit for the last year",
            lines=2
        )

    ask_button = gr.Button("Run Analysis", variant="primary")

    answer_output = gr.Textbox(
        label="Answer",
        lines=8,
        interactive=False
    )

    ask_button.click(
        fn=gradio_ask,
        inputs=question_input,
        outputs=answer_output
    )



@app.get("/")
def root():
    return {
        "status": "ok",
        "message": "AI Analytics Agent is running"
    }



@app.get("/health")
def health_check():
    return {"status": "ok"}

@app.post("/ask")
def ask(question: str):
    answer = ask_tableau_agent(question)
    return {
        "question": question,
        "answer": answer
    }


app = gr.mount_gradio_app(app, gradio_ui, path="/ui")