File size: 12,305 Bytes
745f62a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Quick API test for Sakhi — hits the running Gradio app via HTTP."""
import json
import requests
import time

BASE = "http://localhost:7860"

TESTS = {
    "ANC Normal": {
        "transcript": "ASHA: \u0928\u092e\u0938\u094d\u0924\u0947, \u0915\u0948\u0938\u0947 \u0939\u0948\u0902 \u0906\u092a?\nPatient: \u0928\u092e\u0938\u094d\u0924\u0947 \u0926\u0940\u0926\u0940, \u092e\u0948\u0902 \u0920\u0940\u0915 \u0939\u0942\u0901\u0964\nASHA: \u0905\u091a\u094d\u091b\u093e \u0939\u0948\u0964 \u092e\u0948\u0902 \u0906\u092a\u0915\u093e \u091a\u0947\u0915\u0905\u092a \u0915\u0930\u0928\u0947 \u0906\u0908 \u0939\u0942\u0901\u0964 \u091a\u0932\u093f\u090f, \u092a\u0939\u0932\u0947 \u0906\u092a\u0915\u093e BP \u091a\u0947\u0915 \u0915\u0930 \u0932\u0947\u0924\u0940 \u0939\u0942\u0901\u0964\nPatient: \u0920\u0940\u0915 \u0939\u0948\u0964\nASHA: \u0906\u092a\u0915\u093e BP 110/70 \u0939\u0948, \u092c\u093f\u0932\u094d\u0915\u0941\u0932 \u0920\u0940\u0915 \u0939\u0948\u0964 \u0905\u092c \u0935\u091c\u0928 \u0926\u0947\u0916\u0924\u0940 \u0939\u0942\u0901... 58 kg \u0939\u0948\u0964 \u092a\u093f\u091b\u0932\u0940 \u092c\u093e\u0930 56 \u0925\u093e, \u0924\u094b \u0905\u091a\u094d\u091b\u093e \u092c\u0922\u093c \u0930\u0939\u093e \u0939\u0948\u0964\nPatient: \u0939\u093e\u0901, \u092e\u0948\u0902 \u0905\u091a\u094d\u091b\u093e \u0916\u093e \u0930\u0939\u0940 \u0939\u0942\u0901\u0964\nASHA: \u092c\u0939\u0941\u0924 \u0905\u091a\u094d\u091b\u093e! Hb \u0915\u093f\u0924\u0928\u093e \u0906\u092f\u093e \u0925\u093e \u092a\u093f\u091b\u0932\u0940 \u092c\u093e\u0930?\nPatient: \u0921\u0949\u0915\u094d\u091f\u0930 \u0928\u0947 \u0915\u0939\u093e \u0925\u093e 11.5 \u0939\u0948\u0964\nASHA: \u092f\u0947 \u0924\u094b \u092c\u0939\u0941\u0924 \u0905\u091a\u094d\u091b\u093e \u0939\u0948\u0964 IFA \u0915\u0940 \u0917\u094b\u0932\u093f\u092f\u093e\u0901 \u0932\u0947 \u0930\u0939\u0940 \u0939\u0948\u0902?\nPatient: \u0939\u093e\u0901, \u0930\u094b\u091c\u093c \u0932\u0947\u0924\u0940 \u0939\u0942\u0901\u0964\nASHA: TT \u0915\u093e \u091f\u0940\u0915\u093e \u0932\u0917\u093e?\nPatient: \u0939\u093e\u0901, \u092a\u0939\u0932\u093e \u0932\u0917 \u0917\u092f\u093e \u0939\u0948\u0964\nASHA: \u092c\u091a\u094d\u091a\u0947 \u0915\u0940 \u0939\u0932\u091a\u0932 \u0915\u0948\u0938\u0940 \u0939\u0948?\nPatient: \u092c\u0939\u0941\u0924 \u0939\u093f\u0932\u0924\u093e-\u0921\u0941\u0932\u0924\u093e \u0939\u0948, \u0920\u0940\u0915 \u0939\u0948\u0964\nASHA: \u092c\u0939\u0941\u0924 \u0905\u091a\u094d\u091b\u093e\u0964 \u0906\u092a \u0932\u0917\u092d\u0917 24 \u0939\u092b\u093c\u094d\u0924\u0947 \u0915\u0940 \u0939\u0948\u0902\u0964 \u0921\u093f\u0932\u0940\u0935\u0930\u0940 \u0915\u0947 \u0932\u093f\u090f \u0915\u0939\u093e\u0901 \u091c\u093e\u090f\u0901\u0917\u0940?\nPatient: PHC \u092e\u0947\u0902\u0964\nASHA: \u0917\u093e\u0921\u093c\u0940 \u0915\u093e \u0907\u0902\u0924\u091c\u093c\u093e\u092e \u0939\u0948?\nPatient: \u0939\u093e\u0901, \u092a\u0924\u093f \u0915\u0940 \u0917\u093e\u0921\u093c\u0940 \u0939\u0948\u0964\nASHA: \u0920\u0940\u0915 \u0939\u0948\u0964 \u0905\u0917\u0932\u0940 \u092c\u093e\u0930 2 \u0939\u092b\u093c\u094d\u0924\u0947 \u092c\u093e\u0926 \u0906\u0930\u0942\u0901\u0917\u0940\u0964 \u0915\u094b\u0908 \u0924\u0915\u0932\u0940\u092b\u093c \u0939\u094b \u0924\u094b \u092b\u093c\u094b\u0928 \u0915\u0930 \u0926\u0940\u091c\u093f\u090f\u0964\nPatient: \u0920\u0940\u0915 \u0939\u0948 \u0926\u0940\u0926\u0940, \u0927\u0928\u094d\u092f\u0935\u093e\u0926\u0964",
        "visit_type": "Auto-detect",
        "expect_danger": False,
        "expect_fields": ["110", "70", "58.0", "11.5"],
    },
    "ANC Preeclampsia DANGER": {
        "transcript": "ASHA: \u0928\u092e\u0938\u094d\u0924\u0947 \u0926\u0940\u0926\u0940, \u0915\u0948\u0938\u0947 \u0939\u0948\u0902?\nPatient: \u0926\u0940\u0926\u0940, \u092e\u0941\u091d\u0947 \u092c\u0939\u0941\u0924 \u0938\u093f\u0930\u0926\u0930\u094d\u0926 \u0939\u094b \u0930\u0939\u093e \u0939\u0948 \u0915\u0932 \u0938\u0947\u0964\nASHA: \u0905\u091a\u094d\u091b\u093e, \u0914\u0930 \u0915\u094b\u0908 \u0924\u0915\u0932\u0940\u092b\u093c?\nPatient: \u0939\u093e\u0901, \u0906\u0901\u0916\u094b\u0902 \u0915\u0947 \u0938\u093e\u092e\u0928\u0947 \u0927\u0941\u0902\u0927\u0932\u093e \u0926\u093f\u0916\u0924\u093e \u0939\u0948 \u0915\u092d\u0940-\u0915\u092d\u0940\u0964 \u0914\u0930 \u091a\u0947\u0939\u0930\u0947 \u092a\u0930 \u0938\u0942\u091c\u0928 \u092d\u0940 \u0906 \u0917\u0908 \u0939\u0948\u0964\nASHA: \u092f\u0947 \u0924\u094b \u0920\u0940\u0915 \u0928\u0939\u0940\u0902 \u0939\u0948\u0964 \u092e\u0948\u0902 BP \u091a\u0947\u0915 \u0915\u0930\u0924\u0940 \u0939\u0942\u0901... \u0906\u092a\u0915\u093e BP 155/100 \u0906 \u0930\u0939\u093e \u0939\u0948\u0964 \u092f\u0947 \u092c\u0939\u0941\u0924 \u091c\u093c\u094d\u092f\u093e\u0926\u093e \u0939\u0948\u0964\nPatient: \u0915\u094d\u092f\u093e \u0915\u0930\u0947\u0902 \u0926\u0940\u0926\u0940?\nASHA: \u0906\u092a\u0915\u094b \u0924\u0941\u0930\u0902\u0924 PHC \u091c\u093e\u0928\u093e \u0939\u094b\u0917\u093e\u0964 \u092f\u0947 \u0917\u0902\u092d\u0940\u0930 \u0939\u094b \u0938\u0915\u0924\u093e \u0939\u0948\u0964 \u0906\u092a \u0915\u093f\u0924\u0928\u0947 \u092e\u0939\u0940\u0928\u0947 \u0915\u0940 \u0939\u0948\u0902?\nPatient: \u0932\u0917\u092d\u0917 8 \u092e\u0939\u0940\u0928\u0947\u0964\nASHA: \u092a\u0948\u0930\u094b\u0902 \u092e\u0947\u0902 \u0938\u0942\u091c\u0928 \u0939\u0948?\nPatient: \u0939\u093e\u0901, \u0915\u093e\u092b\u093c\u0940 \u0938\u0942\u091c\u0928 \u0939\u0948\u0964\nASHA: \u092e\u0948\u0902 \u0905\u092d\u0940 \u0917\u093e\u0921\u093c\u0940 \u0915\u093e \u0907\u0902\u0924\u091c\u093c\u093e\u092e \u0915\u0930\u0924\u0940 \u0939\u0942\u0901\u0964 \u0906\u092a\u0915\u094b \u0906\u091c \u0939\u0940 PHC \u0932\u0947 \u091a\u0932\u0924\u0940 \u0939\u0942\u0901\u0964",
        "visit_type": "Auto-detect",
        "expect_danger": True,
        "expect_fields": ["155", "100"],
    },
    "PNC Newborn DANGER": {
        "transcript": "ASHA: \u0928\u092e\u0938\u094d\u0924\u0947, \u0915\u0948\u0938\u0947 \u0939\u0948\u0902? \u092c\u091a\u094d\u091a\u093e \u0915\u0948\u0938\u093e \u0939\u0948?\nMother: \u0926\u0940\u0926\u0940, \u092c\u091a\u094d\u091a\u093e \u092c\u0939\u0941\u0924 \u0938\u094b\u0924\u093e \u0930\u0939\u0924\u093e \u0939\u0948\u0964 \u0926\u0942\u0927 \u092d\u0940 \u0920\u0940\u0915 \u0938\u0947 \u0928\u0939\u0940\u0902 \u092a\u0940\u0924\u093e\u0964\nASHA: \u0915\u092c \u0938\u0947 \u0910\u0938\u093e \u0939\u0948?\nMother: \u0915\u0932 \u0938\u0947\u0964 \u092a\u0939\u0932\u0947 \u0920\u0940\u0915 \u0925\u093e, \u0905\u092c \u0932\u0917\u092d\u0917 12 \u0918\u0902\u091f\u0947 \u0938\u0947 \u0926\u0942\u0927 \u0928\u0939\u0940\u0902 \u092a\u093f\u092f\u093e\u0964\nASHA: \u092c\u091a\u094d\u091a\u0947 \u0915\u093e \u0930\u094b\u0928\u093e \u0915\u0948\u0938\u093e \u0939\u0948?\nMother: \u092c\u0939\u0941\u0924 \u0915\u092e\u091c\u093c\u094b\u0930 \u0906\u0935\u093e\u091c\u093c \u092e\u0947\u0902 \u0930\u094b\u0924\u093e \u0939\u0948\u0964\nASHA: \u0924\u093e\u092a\u092e\u093e\u0928 \u091a\u0947\u0915 \u0915\u0930\u0924\u0940 \u0939\u0942\u0901... 100.5 \u0921\u093f\u0917\u094d\u0930\u0940 \u0939\u0948\u0964 \u092c\u0941\u0916\u093e\u0930 \u0939\u0948\u0964 \u0914\u0930 \u092c\u091a\u094d\u091a\u093e \u0938\u0941\u0938\u094d\u0924 \u0932\u0917 \u0930\u0939\u093e \u0939\u0948\u0964\nMother: \u0915\u094d\u092f\u093e \u0915\u0930\u0947\u0902?\nASHA: \u092f\u0947 IMNCI \u0915\u0947 danger signs \u0939\u0948\u0902\u0964 \u092c\u091a\u094d\u091a\u0947 \u0915\u094b \u0924\u0941\u0930\u0902\u0924 PHC \u0932\u0947 \u091c\u093e\u0928\u093e \u0939\u094b\u0917\u093e\u0964 \u092e\u0948\u0902 \u0917\u093e\u0921\u093c\u0940 \u092c\u0941\u0932\u093e\u0924\u0940 \u0939\u0942\u0901\u0964",
        "visit_type": "Auto-detect",
        "expect_danger": True,
        "expect_fields": [],
    },
    "Child Health Routine": {
        "transcript": "ASHA: \u0928\u092e\u0938\u094d\u0924\u0947, \u092c\u091a\u094d\u091a\u093e \u0915\u0948\u0938\u093e \u0939\u0948?\nMother: \u092c\u093f\u0932\u094d\u0915\u0941\u0932 \u0920\u0940\u0915 \u0939\u0948 \u0926\u0940\u0926\u0940\u0964 \u0916\u0942\u092c \u0916\u093e\u0924\u093e \u0939\u0948, \u0916\u0947\u0932\u0924\u093e \u0939\u0948\u0964\nASHA: \u092c\u0939\u0941\u0924 \u0905\u091a\u094d\u091b\u093e! \u0935\u091c\u0928 \u0926\u0947\u0916\u0924\u0940 \u0939\u0942\u0901... 8.5 kg \u0939\u0948\u0964 9 \u092e\u0939\u0940\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0905\u091a\u094d\u091b\u093e \u0939\u0948\u0964\nMother: \u0939\u093e\u0901, \u0926\u093e\u0932-\u091a\u093e\u0935\u0932, \u0915\u0947\u0932\u093e \u0938\u092c \u0916\u093e\u0924\u093e \u0939\u0948 \u0905\u092c\u0964\nASHA: Vitamin A \u0915\u0940 \u0926\u0935\u093e\u0908 \u0926\u0940 \u0925\u0940 \u092a\u093f\u091b\u0932\u0940 \u092c\u093e\u0930?\nMother: \u0939\u093e\u0901, 6 \u092e\u0939\u0940\u0928\u0947 \u092e\u0947\u0902 \u0926\u0940 \u0925\u0940\u0964\nASHA: \u0905\u091a\u094d\u091b\u093e\u0964 \u0905\u092c deworming \u092d\u0940 \u0926\u0947\u0928\u0940 \u0939\u0948\u0964 \u0914\u0930 \u091f\u0940\u0915\u0947 \u0938\u092c \u0932\u0917\u0947 \u0939\u0948\u0902?\nMother: \u0939\u093e\u0901, \u0938\u092c \u0938\u092e\u092f \u092a\u0930 \u0932\u0917\u0947 \u0939\u0948\u0902\u0964\nASHA: \u092c\u0939\u0941\u0924 \u0905\u091a\u094d\u091b\u093e\u0964 \u092c\u091a\u094d\u091a\u093e \u092c\u0948\u0920\u0924\u093e \u0939\u0948, \u0918\u0941\u091f\u0928\u094b\u0902 \u092a\u0930 \u091a\u0932\u0924\u093e \u0939\u0948?\nMother: \u0939\u093e\u0901, \u0938\u092c \u0915\u0930\u0924\u093e \u0939\u0948\u0964 \u092c\u094b\u0932\u0928\u0947 \u092d\u0940 \u0932\u0917\u093e \u0939\u0948 \u0925\u094b\u0921\u093c\u093e\u0964\nASHA: \u092c\u0922\u093c\u093f\u092f\u093e \u0939\u0948\u0964 \u0905\u0917\u0932\u0940 \u092c\u093e\u0930 3 \u092e\u0939\u0940\u0928\u0947 \u092c\u093e\u0926 \u0906\u0930\u0942\u0901\u0917\u0940\u0964",
        "visit_type": "Auto-detect",
        "expect_danger": False,
        "expect_fields": ["8.5"],
    },
}


def run_tests():
    print("=" * 60)
    print("SAKHI API TEST SUITE")
    print("=" * 60)

    try:
        from gradio_client import Client
    except ImportError:
        import subprocess
        subprocess.run(["pip", "install", "gradio_client", "-q"])
        from gradio_client import Client

    client = Client(BASE, verbose=False)
    passed = 0
    failed = 0

    for name, test in TESTS.items():
        print(f"\n--- {name} ---")
        try:
            result = client.predict(
                transcript=test["transcript"],
                visit_type_override=test["visit_type"],
                api_name="/process_transcript"
            )
            status_html, form_html, danger_html, time_str = result

            has_form = "result-card" in form_html and "error" not in form_html
            has_danger_signs = "Danger Signs Detected" in danger_html
            is_referral = "REFERRAL" in danger_html

            print(f"  Form: {'OK' if has_form else 'FAIL'}")
            print(f"  Danger: {'YES' if has_danger_signs else 'none'}")
            print(f"  Referral: {'YES' if is_referral else 'no'}")
            print(f"  Time: {time_str}")

            ok = True
            if test["expect_danger"] and not has_danger_signs:
                print(f"  FAIL: expected danger signs")
                ok = False
            if not test["expect_danger"] and has_danger_signs:
                print(f"  FAIL: unexpected danger signs")
                ok = False
            if not has_form:
                print(f"  FAIL: no form")
                ok = False

            for val in test["expect_fields"]:
                if val in form_html:
                    print(f"  Field {val}: OK")
                else:
                    print(f"  FAIL: {val} not found")
                    ok = False

            print(f"  {'PASSED' if ok else 'FAILED'}")
            if ok:
                passed += 1
            else:
                failed += 1

        except Exception as e:
            print(f"  ERROR: {type(e).__name__}: {str(e)[:80]}")
            failed += 1

    print(f"\n{'=' * 60}")
    print(f"RESULTS: {passed}/{len(TESTS)} passed")
    print(f"{'=' * 60}")


if __name__ == "__main__":
    run_tests()