Spaces:
Runtime error
Runtime error
adding explanations at the end
Browse files
app.py
CHANGED
@@ -1,39 +1,8 @@
|
|
1 |
import spacy_streamlit
|
2 |
from spacy.symbols import *
|
3 |
import streamlit as st
|
4 |
-
import html
|
5 |
import spacy
|
6 |
-
|
7 |
-
|
8 |
-
from htbuilder import H, HtmlElement, styles
|
9 |
-
from htbuilder.units import unit
|
10 |
-
|
11 |
-
# Only works in 3.7+: from htbuilder import div, span
|
12 |
-
div = H.div
|
13 |
-
span = H.span
|
14 |
-
|
15 |
-
# Only works in 3.7+: from htbuilder.units import px, rem, em
|
16 |
-
px = unit.px
|
17 |
-
rem = unit.rem
|
18 |
-
em = unit.em
|
19 |
-
|
20 |
-
# Colors from the Streamlit palette.
|
21 |
-
# These are red-70, orange-70, ..., violet-70, gray-70.
|
22 |
-
PALETTE = [
|
23 |
-
"#ff4b4b",
|
24 |
-
"#ffa421",
|
25 |
-
"#ffe312",
|
26 |
-
"#21c354",
|
27 |
-
"#00d4b1",
|
28 |
-
"#00c0f2",
|
29 |
-
"#1c83e1",
|
30 |
-
"#803df5",
|
31 |
-
"#808495",
|
32 |
-
]
|
33 |
-
|
34 |
-
OPACITIES = [
|
35 |
-
"33", "66",
|
36 |
-
]
|
37 |
|
38 |
DEFAULT_TEXT = """AI has reached superhuman levels in various areas such as playing complex strategic and video games, calculating protein folding, and visual recognition. Are we close to superhuman levels in conversational AI as well?"""
|
39 |
|
@@ -41,84 +10,13 @@ spacy_model = "en_core_web_sm"
|
|
41 |
|
42 |
replacement_dict= {
|
43 |
"superhuman levels" : "high accuracy",
|
44 |
-
"conversational AI" : "language generation"
|
45 |
}
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
"""
|
52 |
-
|
53 |
-
color_style = {}
|
54 |
-
|
55 |
-
if color:
|
56 |
-
color_style['color'] = color
|
57 |
-
|
58 |
-
if not background:
|
59 |
-
label_sum = sum(ord(c) for c in label)
|
60 |
-
background_color = PALETTE[label_sum % len(PALETTE)]
|
61 |
-
background_opacity = OPACITIES[label_sum % len(OPACITIES)]
|
62 |
-
background = background_color + background_opacity
|
63 |
-
|
64 |
-
return (
|
65 |
-
span(
|
66 |
-
style=styles(
|
67 |
-
background=background,
|
68 |
-
border_radius=rem(0.33),
|
69 |
-
padding=(rem(0.125), rem(0.5)),
|
70 |
-
overflow="hidden",
|
71 |
-
**color_style,
|
72 |
-
**style,
|
73 |
-
))(
|
74 |
-
|
75 |
-
html.escape(body),
|
76 |
-
|
77 |
-
span(
|
78 |
-
style=styles(
|
79 |
-
padding_left=rem(0.5),
|
80 |
-
text_transform="uppercase",
|
81 |
-
))(
|
82 |
-
span(
|
83 |
-
style=styles(
|
84 |
-
font_size=em(0.67),
|
85 |
-
opacity=0.5,
|
86 |
-
))(
|
87 |
-
html.escape(label),
|
88 |
-
),
|
89 |
-
),
|
90 |
-
)
|
91 |
-
)
|
92 |
-
|
93 |
-
|
94 |
-
def get_annotated_html(*args):
|
95 |
-
|
96 |
-
out = div()
|
97 |
-
|
98 |
-
for arg in args:
|
99 |
-
if isinstance(arg, str):
|
100 |
-
out(html.escape(arg))
|
101 |
-
|
102 |
-
elif isinstance(arg, HtmlElement):
|
103 |
-
out(arg)
|
104 |
-
|
105 |
-
elif isinstance(arg, tuple):
|
106 |
-
out(annotation(*arg))
|
107 |
-
|
108 |
-
elif isinstance(arg,list):
|
109 |
-
for el in arg:
|
110 |
-
if isinstance(el, str):
|
111 |
-
out(html.escape(el))
|
112 |
-
|
113 |
-
elif isinstance(el, HtmlElement):
|
114 |
-
out(el)
|
115 |
-
|
116 |
-
elif isinstance(el, tuple):
|
117 |
-
out(annotation(*el))
|
118 |
-
else:
|
119 |
-
raise Exception("Oh noes!")
|
120 |
-
|
121 |
-
return str(out)
|
122 |
|
123 |
st.title("AI Hype Checker")
|
124 |
text = st.text_area("Paste your over-hyped text here:", DEFAULT_TEXT, height=100)
|
@@ -146,5 +44,11 @@ for f in flagged_chunks:
|
|
146 |
unsafe_allow_html=True,
|
147 |
)
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
|
150 |
#st.text(f"Analyzed using spaCy model {spacy_model}")
|
|
|
1 |
import spacy_streamlit
|
2 |
from spacy.symbols import *
|
3 |
import streamlit as st
|
|
|
4 |
import spacy
|
5 |
+
from annotator import get_annotated_html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
DEFAULT_TEXT = """AI has reached superhuman levels in various areas such as playing complex strategic and video games, calculating protein folding, and visual recognition. Are we close to superhuman levels in conversational AI as well?"""
|
8 |
|
|
|
10 |
|
11 |
replacement_dict= {
|
12 |
"superhuman levels" : "high accuracy",
|
13 |
+
"conversational AI" : "natural language generation"
|
14 |
}
|
15 |
|
16 |
+
definitions = {
|
17 |
+
"natural language generation" : "The subfield of artificial intelligence and computational linguistics that is concerned with the construction of computer systems than can produce understandable texts in English or other human languages from some underlying non-linguistic representation of information (Source: [Wikipedia](https://en.wikipedia.org/wiki/Natural_language_generation))",
|
18 |
+
"high accuracy" : "Accuracy is how close or far off a given set of measurements (observations or readings) are to their true value. (Source: [Wikipedia](https://en.wikipedia.org/wiki/Accuracy_and_precision)) "
|
19 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
st.title("AI Hype Checker")
|
22 |
text = st.text_area("Paste your over-hyped text here:", DEFAULT_TEXT, height=100)
|
|
|
44 |
unsafe_allow_html=True,
|
45 |
)
|
46 |
|
47 |
+
st.markdown("***")
|
48 |
+
|
49 |
+
with st.expander("See a definition of these terms"):
|
50 |
+
for f in flagged_chunks:
|
51 |
+
st.write("**"+f[1]+"**", ": " , definitions[f[1]])
|
52 |
+
|
53 |
|
54 |
#st.text(f"Analyzed using spaCy model {spacy_model}")
|