File size: 4,675 Bytes
d06903c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
115
116
117
118
119
120
121
122
123
124
125
126
"""Public Hugging Face UI backed by the actual NVIQ v0.2 engine."""
import tempfile
from pathlib import Path

import gradio as gr

from nviq.errors import NVIQError
from nviq.space_service import audit_files, score_files


def _needed(*files):
    if any(not path for path in files):
        raise gr.Error("Upload every required JSON file before running NVIQ.")


def _score(case_file, observations_file):
    _needed(case_file, observations_file)
    output_dir = Path(tempfile.mkdtemp(prefix="nviq-score-"))
    try:
        result = score_files(
            Path(case_file), Path(observations_file), output_dir
        )
    except (NVIQError, OSError, ValueError, KeyError, TypeError) as exc:
        raise gr.Error(f"NVIQ rejected the supplied data: {exc}") from exc
    return result["summary"], result["report"], str(result["paths"]["json"])


def _audit(case_file, evidence_file, manifest_file):
    _needed(case_file, evidence_file, manifest_file)
    output_dir = Path(tempfile.mkdtemp(prefix="nviq-audit-"))
    try:
        result = audit_files(
            Path(case_file),
            Path(evidence_file),
            Path(manifest_file),
            output_dir,
        )
    except (NVIQError, OSError, ValueError, KeyError, TypeError) as exc:
        raise gr.Error(f"NVIQ rejected the supplied data: {exc}") from exc
    paths = result["paths"]
    downloads = [
        str(paths[key])
        for key in ("json", "html", "snapshot", "derived_observations", "evidence_summary")
    ]
    return result["summary"], downloads


with gr.Blocks(title="NVIQ Open | Noct-Tech") as demo:
    gr.Markdown(
        """
# NVIQ Open
### Noct-Tech · Voice Intelligence Quotient

**Real benchmark scoring and evidence-driven audits**, powered by the
[NVIQ open-source engine](https://github.com/joeking6989/NVIQ-open).

Upload your own valid NVIQ JSON input files. NVIQ does not create provider
measurements or invent observations. **This Space does not call live providers.**

**Public-service privacy:** Never upload credentials, private customer
recordings or transcripts, regulated personal information or confidential data.
        """
    )
    with gr.Tab("Benchmark observations"):
        gr.Markdown(
            "Score existing observations using NVIQ v0.2. "
            "You need a test-case JSON array and an observations JSON array."
        )
        with gr.Row():
            score_cases = gr.File(
                label="NVIQ test cases (.json)", file_types=[".json"], type="filepath"
            )
            score_observations = gr.File(
                label="Recorded observations (.json)",
                file_types=[".json"],
                type="filepath",
            )
        score_button = gr.Button("Run NVIQ benchmark", variant="primary")
        score_summary = gr.JSON(label="Benchmark summary")
        score_report = gr.JSON(label="Full benchmark result")
        score_download = gr.File(label="Download benchmark report (.json)")
        score_button.click(
            _score,
            inputs=[score_cases, score_observations],
            outputs=[score_summary, score_report, score_download],
        )

    with gr.Tab("Evidence-driven audit"):
        gr.Markdown(
            "Run the NVIQ v0.1 execution/audit path against supplied "
            "provider-neutral evidence. Upload the matching cases, evidence and "
            "manifest. The uploaded cases are used directly; the manifest's "
            "case_set field is never treated as a server-side file path."
        )
        audit_cases = gr.File(
            label="NVIQ test cases (.json)", file_types=[".json"], type="filepath"
        )
        audit_evidence = gr.File(
            label="Evidence Bundle (.json)", file_types=[".json"], type="filepath"
        )
        audit_manifest = gr.File(
            label="Audit manifest (.json)", file_types=[".json"], type="filepath"
        )
        audit_button = gr.Button("Execute NVIQ audit", variant="primary")
        audit_summary = gr.JSON(label="Audit summary and coverage")
        audit_downloads = gr.File(
            label="Download audit artifacts (JSON / HTML)", file_count="multiple"
        )
        audit_button.click(
            _audit,
            inputs=[audit_cases, audit_evidence, audit_manifest],
            outputs=[audit_summary, audit_downloads],
        )

    gr.Markdown(
        "[NVIQ source and input formats](https://github.com/joeking6989/NVIQ-open) "
        "· [Noct-Tech](https://noct-tech.com.au)"
    )


if __name__ == "__main__":
    demo.queue(default_concurrency_limit=2, max_size=8).launch(
        max_file_size="5mb",
        show_error=False,
    )