File size: 2,748 Bytes
9bf65dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""One-time helper to insert the A12 Gradio tab into the existing app.py.

Run from the repository root:
    python3 app_a12_patch.py

The script is intentionally small and conservative: it adds one import and one
new tab, but does not rewrite the rest of app.py.
"""

from pathlib import Path

APP_PATH = Path("app.py")

IMPORT_LINE = "from A12.service.ui import run_a12_tab\n"
AFTER_IMPORT = "from A12.pose_interpolator import smooth_pose_sequence\n"

TAB_CODE = '''

        # A12 Classifier Tab
        with gr.TabItem("🧪 A12 Classifier"):
            gr.Markdown(
                """
                ### A12 Service Endpoint: Pose CSV classifier

                Endpoint alternative chosen: **Gradio tab inside the existing app**.
                This keeps the HuggingFace Space architecture simple and avoids a
                separate REST/FastAPI service. Upload a pose-feature CSV exported
                with the same feature schema used by the A12 classifier.
                """
            )
            with gr.Row():
                with gr.Column():
                    a12_csv_input = gr.File(
                        label="Pose feature CSV",
                        file_types=[".csv"],
                        type="filepath",
                    )
                    a12_problem_input = gr.Radio(
                        choices=["A", "B"],
                        value="B",
                        label="Classifier problem",
                        info="A = Kinect 3D features, B = PoseNet 2D features",
                    )
                    a12_predict_btn = gr.Button("Run A12 classifier", variant="primary")

                with gr.Column():
                    a12_summary_output = gr.Markdown(label="Summary")
                    a12_json_output = gr.JSON(label="Structured JSON output")

            a12_predict_btn.click(
                fn=run_a12_tab,
                inputs=[a12_csv_input, a12_problem_input],
                outputs=[a12_json_output, a12_summary_output],
            )
'''

INSERT_BEFORE = "    # Example section\n"


def main() -> None:
    text = APP_PATH.read_text()

    if IMPORT_LINE not in text:
        if AFTER_IMPORT not in text:
            raise RuntimeError("Could not find A12 pose_interpolator import line.")
        text = text.replace(AFTER_IMPORT, AFTER_IMPORT + IMPORT_LINE, 1)

    if "with gr.TabItem(\"🧪 A12 Classifier\")" not in text:
        if INSERT_BEFORE not in text:
            raise RuntimeError("Could not find location for the A12 tab insertion.")
        text = text.replace(INSERT_BEFORE, TAB_CODE + "\n" + INSERT_BEFORE, 1)

    APP_PATH.write_text(text)
    print("A12 Gradio tab inserted into app.py")


if __name__ == "__main__":
    main()