Spaces:
Sleeping
Sleeping
more colors
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from io import StringIO
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
import pandas as pd
|
@@ -9,6 +10,7 @@ nlp = spacy.load('en_core_web_sm')
|
|
9 |
|
10 |
HTML_RED = '<span style="background-color: rgba(255, 0, 0, 0.2)">{t}</span>'
|
11 |
HTML_GRN = '<span style="background-color: rgba(0, 255, 0, 0.3)">{t}</span>'
|
|
|
12 |
HTML_BLU = '<span style="background-color: rgba(0, 0, 255, 0.2)">{t}</span>'
|
13 |
HTML_PLN = '<span>{t}</span>'
|
14 |
TABLE_CSS = '''
|
@@ -22,6 +24,7 @@ table, th, td {
|
|
22 |
}
|
23 |
'''
|
24 |
|
|
|
25 |
def colorize(file_obj):
|
26 |
with open(file_obj.name, 'r') as f:
|
27 |
raw = f.read()
|
@@ -37,9 +40,26 @@ def colorize(file_obj):
|
|
37 |
row[1]['model summary A'],
|
38 |
row[1]['model summary B']
|
39 |
))
|
40 |
-
tokens_gold = {token.lemma_.lower() for token in gold}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
table_content.append(
|
42 |
-
[id_,
|
43 |
[
|
44 |
''.join(
|
45 |
(
|
@@ -88,6 +108,30 @@ def main():
|
|
88 |
)
|
89 |
run = gr.Button(label='Run')
|
90 |
with gr.TabItem("Visualization"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
viz = gr.HTML(label='Upload a csv file to start.')
|
92 |
run.click(colorize, data, viz)
|
93 |
|
|
|
1 |
from io import StringIO
|
2 |
+
import itertools
|
3 |
|
4 |
import gradio as gr
|
5 |
import pandas as pd
|
|
|
10 |
|
11 |
HTML_RED = '<span style="background-color: rgba(255, 0, 0, 0.2)">{t}</span>'
|
12 |
HTML_GRN = '<span style="background-color: rgba(0, 255, 0, 0.3)">{t}</span>'
|
13 |
+
HTML_YLW = '<span style="background-color: rgba(255, 255, 0, 0.3)">{t}</span>'
|
14 |
HTML_BLU = '<span style="background-color: rgba(0, 0, 255, 0.2)">{t}</span>'
|
15 |
HTML_PLN = '<span>{t}</span>'
|
16 |
TABLE_CSS = '''
|
|
|
24 |
}
|
25 |
'''
|
26 |
|
27 |
+
|
28 |
def colorize(file_obj):
|
29 |
with open(file_obj.name, 'r') as f:
|
30 |
raw = f.read()
|
|
|
40 |
row[1]['model summary A'],
|
41 |
row[1]['model summary B']
|
42 |
))
|
43 |
+
tokens_gold = {token.lemma_.lower(): 0 for token in gold}
|
44 |
+
for token in itertools.chain(genA, genB):
|
45 |
+
if token.lemma_.lower() in tokens_gold:
|
46 |
+
tokens_gold[token.lemma_.lower()] += 1
|
47 |
+
|
48 |
+
gold_text = ''.join([
|
49 |
+
(
|
50 |
+
HTML_PLN.format(t=token.text)
|
51 |
+
if token.pos_ not in {'NOUN', 'PROPN', 'VERB'}
|
52 |
+
else (
|
53 |
+
(
|
54 |
+
HTML_BLU if tokens_gold[token.lemma_.lower()] > 0
|
55 |
+
else HTML_YLW
|
56 |
+
).format(t=token.text)
|
57 |
+
)
|
58 |
+
) + token.whitespace_
|
59 |
+
for token in gold
|
60 |
+
])
|
61 |
table_content.append(
|
62 |
+
[id_, gold_text] +
|
63 |
[
|
64 |
''.join(
|
65 |
(
|
|
|
108 |
)
|
109 |
run = gr.Button(label='Run')
|
110 |
with gr.TabItem("Visualization"):
|
111 |
+
gr.HTML(
|
112 |
+
''.join(
|
113 |
+
(
|
114 |
+
"<b>Explanation of colors:</b>",
|
115 |
+
"<br><ul>",
|
116 |
+
"<li><b>",
|
117 |
+
HTML_RED.format(t='Red'),
|
118 |
+
"</b>: word is in generated, but not in gold.</li>",
|
119 |
+
"<li><b>",
|
120 |
+
HTML_GRN.format(t='Green'),
|
121 |
+
"</b>: word is in generated summary and gold.</li>",
|
122 |
+
"<li><b>",
|
123 |
+
HTML_YLW.format(t='Yellow'),
|
124 |
+
"</b>: word is in gold, but not in generated.</li>",
|
125 |
+
"<li><b>",
|
126 |
+
HTML_BLU.format(t='Blue'),
|
127 |
+
"</b>: word is in gold and in generated.</li>",
|
128 |
+
"</ul>",
|
129 |
+
"<br>",
|
130 |
+
"<b>Important</b>: Only nouns, verbs and proper ",
|
131 |
+
"nouns are colored.</b>"
|
132 |
+
)
|
133 |
+
)
|
134 |
+
)
|
135 |
viz = gr.HTML(label='Upload a csv file to start.')
|
136 |
run.click(colorize, data, viz)
|
137 |
|