Spaces:
Runtime error
Runtime error
import spacy_streamlit | |
from spacy.symbols import * | |
import streamlit as st | |
import spacy | |
from annotator import get_annotated_html | |
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?""" | |
spacy_model = "en_core_web_sm" | |
replacement_dict= { | |
"superhuman levels" : "high accuracy", | |
"conversational AI" : "natural language generation" | |
} | |
definitions = { | |
"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))", | |
"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)) " | |
} | |
st.title("AI Hype Checker") | |
text = st.text_area("Paste your over-hyped text here:", DEFAULT_TEXT, height=100) | |
doc = spacy_streamlit.process_text(spacy_model, text) | |
for chunk in doc.noun_chunks: | |
if chunk.text in replacement_dict.keys(): | |
text= text.replace(chunk.text, replacement_dict[chunk.text]) | |
else: | |
continue | |
text = st.text_area("Fixed it! See below:", text, height=100) | |
st.markdown("## Here are the terms that we flagged:") | |
chunks= [chunk.text for chunk in doc.noun_chunks] | |
flagged_chunks=[] | |
for i in range(len(chunks)): | |
if chunks[i] in replacement_dict.keys(): | |
flagged_chunks.append((chunks[i], replacement_dict[chunks[i]])) | |
flagged_chunks = list(set(flagged_chunks)) | |
for f in flagged_chunks: | |
st.markdown( | |
get_annotated_html(f), | |
unsafe_allow_html=True, | |
) | |
st.markdown("***") | |
with st.expander("See a definition of these terms"): | |
for f in flagged_chunks: | |
st.write("**"+f[1]+"**", ": " , definitions[f[1]]) | |
#st.text(f"Analyzed using spaCy model {spacy_model}") | |