""" hv-split-demo -- Gradio Space for the interpretation splitter. Deploy: huggingface-cli repo create hv-split-demo --type space --space-sdk gradio # upload: app.py, hv_split.py, requirements.txt """ import gradio as gr from hv_split import HVInterpret M = HVInterpret() SAMPLES = [ ["I need to access the bank"], ["All that glitters is not gold"], ["Why did the CEO resign last week?"], ["in the language of category theory, what is an identity?"], [ "why did the current bank say recently that the function she " "used in the language of category theory had changed?" ], ["compute 2 + 2"], ] def split(query): if not query.strip(): return "", "", "" b = M.split(query) summary = ( f"ambiguity_score : {b.ambiguity_score:.3f}\n" f"confidence : {b.confidence:.3f}\n" f"sources : {', '.join(b.sources) or '(none)'}\n" f"interpretations : {b.n_interpretations}" ) rows = ["prior source reading"] rows.append("-" * 70) for i in b.interpretations: rows.append(f"{i.prior:.3f} {i.source:<17} {i.reading}") table = "\n".join(rows) md = M.render(b, mode="markdown") return summary, table, md with gr.Blocks(title="hv-split demo") as demo: gr.Markdown( "# hv-split\n" "Split an ambiguous query into a ranked bundle of " "interpretations.\n\n" "**Every generative model picks one reading. This one " "refuses to pick.**" ) with gr.Row(): with gr.Column(): query = gr.Textbox( label="Query", value=SAMPLES[0][0], lines=3 ) btn = gr.Button("Split", variant="primary") with gr.Column(): summary = gr.Textbox(label="Summary", lines=5) table = gr.Textbox(label="Interpretations", lines=14) md = gr.Markdown(label="Markdown") gr.Examples( examples=SAMPLES, inputs=[query], outputs=[summary, table, md], ) btn.click(split, inputs=[query], outputs=[summary, table, md]) if __name__ == "__main__": demo.launch()