browndw commited on
Commit
e57c7ed
1 Parent(s): b89a8fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -53
app.py CHANGED
@@ -1,59 +1,52 @@
1
- import streamlit as st
 
 
 
 
2
  import spacy
3
- from spacytextblob.spacytextblob import SpacyTextBlob
4
- from spacy_streamlit import visualize_ner
5
 
6
- st.header("DocuScope Demo (spaCy)")
7
- st.markdown("This demo uses a trained spaCy model (**en_docusco_spacy**) to identify DocuScope categories in text.")
8
- st.markdown("The is one of a family of models trained on DocuScope.")
9
- st.markdown("NOTE: this demo is public - please don't enter confidential text")
10
 
11
- # Streamlit text boxes
12
- # Text source: https://www.theguardian.com/film/2016/dec/22/jaws-steven-spielberg-1975-review-derek-malcolm
13
- text = st.text_area('Enter text:', value="Jaws is a splendidly shrewd cinematic equation which not only gives you one or two very nasty turns when you least expect them but, possibly more important, knows when to make you think another is coming without actually providing it.")
 
 
 
 
 
14
 
15
 
16
- nlp = spacy.load("en_docusco_spacy")
17
- if text:
18
- doc = nlp(text)
19
- visualize_ner(doc, labels=nlp.get_pipe("ner").labels)
20
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- st.header("Label Explanation")
23
- st.markdown("**Academic Terms:** Abstract, rare, specialized, or disciplinary-specific terms that are indicative of informationally dense writing")
24
- st.markdown("**Academic Writing Moves:** Phrases and terms that indicate academic writing moves, which are common in research genres and are derived from the work of Swales (1981) and Cotos et al. (2015, 2017)")
25
- st.markdown("**Character:** References multiple dimensions of a character or human being as a social agent, both individual and collective")
26
- st.markdown("**Citation:** Language that indicates the attribution of information to, or citation of, another source.")
27
- st.markdown("**Citation Authorized:** Referencing the citation of another source that is represented as true and not arguable")
28
- st.markdown("**Citation Hedged:** Referencing the citation of another source that is presented as arguable")
29
- st.markdown("**Confidence Hedged:** Referencing language that presents a claim as uncertain")
30
- st.markdown("**Confidence High:** Referencing language that presents a claim with certainty")
31
- st.markdown("**Confidence Low:** Referencing language that presents a claim as extremely unlikely")
32
- st.markdown("**Contingent:** Referencing contingency, typically contingency in the world, rather than contingency in one's knowledge")
33
- st.markdown("**Description:** Language that evokes sights, sounds, smells, touches and tastes, as well as scenes and objects")
34
- st.markdown("**Facilitate:** Language that enables or directs one through specific tasks and actions")
35
- st.markdown("**First Person:** This cluster captures first person.")
36
- st.markdown("**Force Stressed:** Language that is forceful and stressed, often using emphatics, comparative forms, or superlative forms")
37
- st.markdown("**Future:** Referencing future actions, states, or desires")
38
- st.markdown("**Information Change:** Referencing changes of information, particularly changes that are more neutral")
39
- st.markdown("**Information Change Negative:** Referencing negative change")
40
- st.markdown("**Information Change Positive:** Referencing positive change")
41
- st.markdown("**Information Exposition:** Information in the form of expository devices, or language that describes or explains, frequently in regards to quantities and comparisons")
42
- st.markdown("**Information Place:** Language designating places")
43
- st.markdown("**Information Report Verbs:** Informational verbs and verb phrases of reporting")
44
- st.markdown("**Information States:** Referencing information states, or states of being")
45
- st.markdown("**Information Topics:** Referencing topics, usually nominal subjects or objects, that indicate the “aboutness” of a text")
46
- st.markdown("**Inquiry:** Referencing inquiry, or language that points to some kind of inquiry or investigation")
47
- st.markdown("**Interactive:** Addresses from the author to the reader or from persons in the text to other persons. The address comes in the language of everyday conversation, colloquy, exchange, questions, attention-getters, feedback, interactive genre markers, and the use of the second person.")
48
- st.markdown("**Metadiscourse Cohesive:** The use of words to build cohesive markers that help the reader navigate the text and signal linkages in the text, which are often additive or contrastive")
49
- st.markdown("**Metadiscourse Interactive:** The use of words to build cohesive markers that interact with the reader")
50
- st.markdown("**Narrative:** Language that involves people, description, and events extending in time")
51
- st.markdown("**Negative:** Referencing dimensions of negativity, including negative acts, emotions, relations, and values")
52
- st.markdown("**Positive:** Referencing dimensions of positivity, including actions, emotions, relations, and values")
53
- st.markdown("**Public Terms:** Referencing public terms, concepts from public language, media, the language of authority, institutions, and responsibility")
54
- st.markdown("**Reasoning:** Language that has a reasoning focus, supporting inferences about cause, consequence, generalization, concession, and linear inference either from premise to conclusion or conclusion to premise")
55
- st.markdown("**Responsibility:** Referencing the language of responsibility")
56
- st.markdown("**Strategic:** This dimension is active when the text structures strategies activism, advantage-seeking, game-playing cognition, plans, and goal-seeking.")
57
- st.markdown("**Syntactic Complexity:** The features in this category are often what are called “function words,” like determiners and prepositions.")
58
- st.markdown("**Uncertainty:** References uncertainty, when confidence levels are unknown.")
59
- st.markdown("**Updates:** References updates that anticipate someone searching for information and receiving it.")
 
1
+ # Core Pkgs
2
+ import streamlit as st
3
+
4
+ # NLP Pkgs
5
+ import spacy_streamlit
6
  import spacy
7
+ import re
 
8
 
9
+ nlp = spacy.load('en_docusco_spacy')
 
 
 
10
 
11
+ def pre_process(txt):
12
+ txt = re.sub(r'\bits\b', 'it s', txt)
13
+ txt = re.sub(r'\bIts\b', 'It s', txt)
14
+ txt = " ".join(txt.split())
15
+ return(txt)
16
+
17
+ #import os
18
+ #from PIL import Image
19
 
20
 
21
+ def main():
22
+
23
+ st.title("DocuScope and Part-of-Speech Tagging with spaCy")
24
+ st.markdown("This demo uses a trained spaCy model ([en_docusco_spacy](https://huggingface.co/browndw/en_docusco_spacy)) to identify DocuScope categories in text.")
25
+ st.markdown("It is also trained on the [CLAWS7](https://ucrel.lancs.ac.uk/claws7tags.html) part-of-speech tagset.")
26
+ st.markdown("NOTE: this demo is public - please don't enter confidential text")
27
+
28
+ #our_image = Image.open(os.path.join('SpaCy_logo.svg.png'))
29
+ #st.image(our_image)
30
+
31
+ menu = ["Tokens","DocuScope"]
32
+ choice = st.sidebar.selectbox("Menu",menu)
33
+
34
+ if choice == "Tokens":
35
+ st.subheader("Tokenization")
36
+ raw_text = st.text_area('Enter text:', value="Jaws is a shrewd cinematic equation which not only gives you one or two very nasty turns when you least expect them but, possibly more important, knows when to make you think another is coming without actually providing it.")
37
+ docx = pre_process(raw_text)
38
+ docx = nlp(docx)
39
+ if st.button("Tokenize"):
40
+ spacy_streamlit.visualize_tokens(docx,attrs=['text','tag_', 'ent_iob_', 'ent_type_'])
41
+
42
+ elif choice == "DocuScope":
43
+ st.subheader("Named Entity Recognition")
44
+ raw_text = st.text_area('Enter text:', value="Jaws is a shrewd cinematic equation which not only gives you one or two very nasty turns when you least expect them but, possibly more important, knows when to make you think another is coming without actually providing it.")
45
+ docx = pre_process(raw_text)
46
+ docx = nlp(docx)
47
+ spacy_streamlit.visualize_ner(docx,labels=nlp.get_pipe('ner').labels)
48
+
49
 
50
+ if __name__ == '__main__':
51
+ main()
52
+