Spaces:
Build error
Build error
Commit
·
1717bf9
1
Parent(s):
5c533e1
improved layout
Browse files
app.py
CHANGED
@@ -44,20 +44,31 @@ config['er_dir'] = os.path.join(model_dir, 'evidence_retrieval/')
|
|
44 |
from src.loren import Loren
|
45 |
|
46 |
|
47 |
-
loren = Loren(config)
|
48 |
try:
|
49 |
js = loren.check('Donald Trump won the 2020 U.S. presidential election.')
|
50 |
except Exception as e:
|
51 |
raise ValueError(e)
|
52 |
|
53 |
|
|
|
|
|
|
|
|
|
54 |
def gradio_formatter(js, output_type):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
if output_type == 'e':
|
56 |
data = {'Evidence': [f'* {x}' for x in js['evidence']]}
|
57 |
elif output_type == 'z':
|
58 |
data = {
|
59 |
-
'Claim Phrase':
|
60 |
-
'Local Premise': [
|
61 |
'p_SUP': ['%.4f' % x[2] for x in js['phrase_veracity']],
|
62 |
'p_REF': ['%.4f' % x[0] for x in js['phrase_veracity']],
|
63 |
'p_NEI': ['%.4f' % x[1] for x in js['phrase_veracity']],
|
@@ -72,6 +83,8 @@ def gradio_formatter(js, output_type):
|
|
72 |
html = pt.get_html_string(attributes={
|
73 |
'style': 'border-width: 2px; bordercolor: black'
|
74 |
}, format=True)
|
|
|
|
|
75 |
return html
|
76 |
|
77 |
|
@@ -88,16 +101,16 @@ def run(claim):
|
|
88 |
js = loren.check(claim)
|
89 |
ev_html = gradio_formatter(js, 'e')
|
90 |
z_html = gradio_formatter(js, 'z')
|
91 |
-
return
|
92 |
|
93 |
|
94 |
iface = gr.Interface(
|
95 |
fn=run,
|
96 |
inputs="text",
|
97 |
outputs=[
|
|
|
98 |
'html',
|
99 |
'html',
|
100 |
-
'label',
|
101 |
'json'
|
102 |
],
|
103 |
examples=['Donald Trump won the U.S. 2020 presidential election.',
|
@@ -112,8 +125,8 @@ iface = gr.Interface(
|
|
112 |
"*Note that the demo system directly retrieves evidence from an up-to-date Wikipedia, which is different from the evidence used in the paper.",
|
113 |
flagging_dir='results/flagged/',
|
114 |
allow_flagging=True,
|
115 |
-
flagging_options=['Good Case!', 'Error:
|
116 |
-
'Error: Commonsense', 'Error: Evidence', 'Error: Other'],
|
117 |
enable_queue=True
|
118 |
)
|
119 |
iface.launch()
|
|
|
44 |
from src.loren import Loren
|
45 |
|
46 |
|
47 |
+
loren = Loren(config, verbose=False)
|
48 |
try:
|
49 |
js = loren.check('Donald Trump won the 2020 U.S. presidential election.')
|
50 |
except Exception as e:
|
51 |
raise ValueError(e)
|
52 |
|
53 |
|
54 |
+
def highlight_phrase(text, phrase):
|
55 |
+
return text.replace('<mask>', f'<i><b>{phrase}</b></i>')
|
56 |
+
|
57 |
+
|
58 |
def gradio_formatter(js, output_type):
|
59 |
+
zebra_css = '''
|
60 |
+
tr:nth-child(even) {
|
61 |
+
background: #f1f1f1;
|
62 |
+
}
|
63 |
+
thead{
|
64 |
+
background: #f1f1f1;
|
65 |
+
}'''
|
66 |
if output_type == 'e':
|
67 |
data = {'Evidence': [f'* {x}' for x in js['evidence']]}
|
68 |
elif output_type == 'z':
|
69 |
data = {
|
70 |
+
'Claim Phrase': js['claim_phrases'],
|
71 |
+
'Local Premise': [highlight_phrase(q, x[0]) for q, x in zip(js['cloze_qs'], js['evidential'])],
|
72 |
'p_SUP': ['%.4f' % x[2] for x in js['phrase_veracity']],
|
73 |
'p_REF': ['%.4f' % x[0] for x in js['phrase_veracity']],
|
74 |
'p_NEI': ['%.4f' % x[1] for x in js['phrase_veracity']],
|
|
|
83 |
html = pt.get_html_string(attributes={
|
84 |
'style': 'border-width: 2px; bordercolor: black'
|
85 |
}, format=True)
|
86 |
+
html = f'<head> <style type="text/css"> {zebra_css} </style> </head>\n' + html
|
87 |
+
html = html.replace('<', '<').replace('>', '>')
|
88 |
return html
|
89 |
|
90 |
|
|
|
101 |
js = loren.check(claim)
|
102 |
ev_html = gradio_formatter(js, 'e')
|
103 |
z_html = gradio_formatter(js, 'z')
|
104 |
+
return js['claim_veracity'], z_html, ev_html, js
|
105 |
|
106 |
|
107 |
iface = gr.Interface(
|
108 |
fn=run,
|
109 |
inputs="text",
|
110 |
outputs=[
|
111 |
+
'label',
|
112 |
'html',
|
113 |
'html',
|
|
|
114 |
'json'
|
115 |
],
|
116 |
examples=['Donald Trump won the U.S. 2020 presidential election.',
|
|
|
125 |
"*Note that the demo system directly retrieves evidence from an up-to-date Wikipedia, which is different from the evidence used in the paper.",
|
126 |
flagging_dir='results/flagged/',
|
127 |
allow_flagging=True,
|
128 |
+
flagging_options=['Good Case!', 'Error: Local Premise', 'Error: Claim Phrase Parsing',
|
129 |
+
'Error: Commonsense Claim', 'Error: Inconsistent Phrase and Claim Veracity', 'Error: Evidence Retrieval', 'Error: Other'],
|
130 |
enable_queue=True
|
131 |
)
|
132 |
iface.launch()
|