File size: 1,563 Bytes
9e16e32
4e83f99
9e16e32
4e83f99
9e16e32
1058ca8
9e16e32
1058ca8
4e83f99
9e16e32
 
4e83f99
1058ca8
9e16e32
 
 
 
 
1058ca8
 
3fcb62a
 
 
 
9e16e32
 
 
 
 
 
 
1058ca8
9e16e32
 
 
 
 
d0f90f1
 
 
9e16e32
1058ca8
3fcb62a
9e16e32
 
 
 
 
 
 
 
 
 
1058ca8
9e16e32
 
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
from typing import Final

import gradio as gr  # type: ignore

import src.func as func

DEFAULT_AMOUNT: Final[int] = 10_000


def clear(text: str) -> str:
    return func.clear(text)


def calculate(budget: int, text: str) -> tuple[str, list[list]]:
    try:
        return func.calculate(budget, text)
    except Exception as e:
        raise gr.Error(e)


with gr.Blocks(
    theme=gr.themes.Default(primary_hue="green", secondary_hue="lime")
) as demo:
    # flontend ------------------------------
    with gr.Row():
        with gr.Column():
            budget_input = gr.Number(value=DEFAULT_AMOUNT, label="ไบˆ็ฎ—")
            text_input = gr.Textbox(label="netkeiba ่ฒทใ„็›ฎใ‚ณใƒ”ใƒš")
            with gr.Row():
                calculate_button = gr.Button(value="Calculate", variant="primary")
                clear_button = gr.Button(value="Clear")

        with gr.Column():
            markdown_output = gr.Markdown()
            df_output = gr.Dataframe(
                value=[],
                label=None,
                headers=["่ฒทใ„็›ฎ", "ใ‚ชใƒƒใ‚บ", "่ณญใ‘้ก", "ๆ‰•ๆˆป"],
                datatype=["str", "number", "number", "number"],
                col_count=(4, "fixed"),
            )

    # click ------------------------------
    calculate_button.click(
        calculate,
        inputs=[budget_input, text_input],
        outputs=[markdown_output, df_output],
    )
    clear_button.click(
        clear,
        inputs=[text_input],
        outputs=[text_input],
    )

if "__main__" == __name__:
    demo.launch(debug=True)