Update app.py
Browse files
app.py
CHANGED
@@ -30,6 +30,7 @@ import os
|
|
30 |
import torch
|
31 |
from transformers import AutoTokenizer, AutoModelWithLMHead
|
32 |
|
|
|
33 |
# NLP Pkgs
|
34 |
from textblob import TextBlob
|
35 |
import spacy
|
@@ -49,7 +50,11 @@ def text_analyzer(my_text):
|
|
49 |
# tokens = [ token.text for token in docx]
|
50 |
allData = [('"Token":{},\n"Lemma":{}'.format(token.text,token.lemma_))for token in docx ]
|
51 |
return allData
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
# Function For Extracting Entities
|
54 |
@st.experimental_singleton
|
55 |
def entity_analyzer(my_text):
|
@@ -68,16 +73,8 @@ def main():
|
|
68 |
+ This is a Natural Language Processing(NLP) Based App useful for basic NLP task
|
69 |
NER,Sentiment, Spell Corrections and Summarization
|
70 |
""")
|
71 |
-
|
72 |
-
#Text Corrections
|
73 |
-
if st.checkbox("Spell Corrections"):
|
74 |
-
st.subheader("Correct Your Text")
|
75 |
-
message = st.text_area("Enter the Text","Type please ..")
|
76 |
-
if st.button("Spell Corrections"):
|
77 |
-
st.text("Using TextBlob ..")
|
78 |
-
st.success(TextBlob(message).correct())
|
79 |
# Entity Extraction
|
80 |
-
|
81 |
st.subheader("Analyze Your Text")
|
82 |
|
83 |
message = st.text_area("Enter your Text","Typing Here ..")
|
@@ -93,6 +90,24 @@ def main():
|
|
93 |
blob = TextBlob(message)
|
94 |
result_sentiment = blob.sentiment
|
95 |
st.success(result_sentiment)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
def change_photo_state():
|
97 |
st.session_state["photo"]="done"
|
98 |
st.subheader("Summary section, feed your image!")
|
|
|
30 |
import torch
|
31 |
from transformers import AutoTokenizer, AutoModelWithLMHead
|
32 |
|
33 |
+
|
34 |
# NLP Pkgs
|
35 |
from textblob import TextBlob
|
36 |
import spacy
|
|
|
50 |
# tokens = [ token.text for token in docx]
|
51 |
allData = [('"Token":{},\n"Lemma":{}'.format(token.text,token.lemma_))for token in docx ]
|
52 |
return allData
|
53 |
+
@st.experimental_singleton
|
54 |
+
def load_models():
|
55 |
+
tokenizer = AutoTokenizer.from_pretrained('gpt2-large')
|
56 |
+
model = GPT2LMHeadModel.from_pretrained('gpt2-large')
|
57 |
+
return tokenizer, model
|
58 |
# Function For Extracting Entities
|
59 |
@st.experimental_singleton
|
60 |
def entity_analyzer(my_text):
|
|
|
73 |
+ This is a Natural Language Processing(NLP) Based App useful for basic NLP task
|
74 |
NER,Sentiment, Spell Corrections and Summarization
|
75 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
# Entity Extraction
|
77 |
+
if st.checkbox("Show Named Entities"):
|
78 |
st.subheader("Analyze Your Text")
|
79 |
|
80 |
message = st.text_area("Enter your Text","Typing Here ..")
|
|
|
90 |
blob = TextBlob(message)
|
91 |
result_sentiment = blob.sentiment
|
92 |
st.success(result_sentiment)
|
93 |
+
#Text Corrections
|
94 |
+
elif st.checkbox("Spell Corrections"):
|
95 |
+
st.subheader("Correct Your Text")
|
96 |
+
message = st.text_area("Enter the Text","Type please ..")
|
97 |
+
if st.button("Spell Corrections"):
|
98 |
+
st.text("Using TextBlob ..")
|
99 |
+
st.success(TextBlob(message).correct())
|
100 |
+
elif st.checkbox("Text Generation"):
|
101 |
+
st.subheader("Generate Text")
|
102 |
+
tokenizer, model = load_models()
|
103 |
+
message = st.text_area("Enter the Text","Type please ..")
|
104 |
+
input_ids = tokenizer(message, return_tensors='pt').input_ids
|
105 |
+
if st.button("Generate"):
|
106 |
+
st.text("Using Hugging Face Trnsformer, Contrastive Search ..")
|
107 |
+
output = model.generate(input_ids, max_length=128)
|
108 |
+
st.success("Output:\n" + 100 * '-')
|
109 |
+
st.success(tokenizer.decode(output[0], skip_special_tokens=True)))
|
110 |
+
st.success("" + 100 * '-')
|
111 |
def change_photo_state():
|
112 |
st.session_state["photo"]="done"
|
113 |
st.subheader("Summary section, feed your image!")
|