zeechimp commited on
Commit
76a4c0e
·
verified ·
1 Parent(s): 46f5741

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ hv-split-demo -- Gradio Space for the interpretation splitter.
3
+
4
+ Deploy:
5
+ huggingface-cli repo create hv-split-demo --type space --space-sdk gradio
6
+ # upload: app.py, hv_split.py, requirements.txt
7
+ """
8
+
9
+ import gradio as gr
10
+
11
+ from hv_split import HVInterpret
12
+
13
+
14
+ M = HVInterpret()
15
+
16
+ SAMPLES = [
17
+ ["I need to access the bank"],
18
+ ["All that glitters is not gold"],
19
+ ["Why did the CEO resign last week?"],
20
+ ["in the language of category theory, what is an identity?"],
21
+ [
22
+ "why did the current bank say recently that the function she "
23
+ "used in the language of category theory had changed?"
24
+ ],
25
+ ["compute 2 + 2"],
26
+ ]
27
+
28
+
29
+ def split(query):
30
+ if not query.strip():
31
+ return "", "", ""
32
+ b = M.split(query)
33
+ summary = (
34
+ f"ambiguity_score : {b.ambiguity_score:.3f}\n"
35
+ f"confidence : {b.confidence:.3f}\n"
36
+ f"sources : {', '.join(b.sources) or '(none)'}\n"
37
+ f"interpretations : {b.n_interpretations}"
38
+ )
39
+ rows = ["prior source reading"]
40
+ rows.append("-" * 70)
41
+ for i in b.interpretations:
42
+ rows.append(f"{i.prior:.3f} {i.source:<17} {i.reading}")
43
+ table = "\n".join(rows)
44
+ md = M.render(b, mode="markdown")
45
+ return summary, table, md
46
+
47
+
48
+ with gr.Blocks(title="hv-split demo") as demo:
49
+ gr.Markdown(
50
+ "# hv-split\n"
51
+ "Split an ambiguous query into a ranked bundle of "
52
+ "interpretations.\n\n"
53
+ "**Every generative model picks one reading. This one "
54
+ "refuses to pick.**"
55
+ )
56
+ with gr.Row():
57
+ with gr.Column():
58
+ query = gr.Textbox(
59
+ label="Query", value=SAMPLES[0][0], lines=3
60
+ )
61
+ btn = gr.Button("Split", variant="primary")
62
+ with gr.Column():
63
+ summary = gr.Textbox(label="Summary", lines=5)
64
+ table = gr.Textbox(label="Interpretations", lines=14)
65
+ md = gr.Markdown(label="Markdown")
66
+
67
+ gr.Examples(
68
+ examples=SAMPLES,
69
+ inputs=[query],
70
+ outputs=[summary, table, md],
71
+ )
72
+
73
+ btn.click(split, inputs=[query], outputs=[summary, table, md])
74
+
75
+
76
+ if __name__ == "__main__":
77
+ demo.launch()