Update app.py
Browse files
app.py
CHANGED
@@ -52,9 +52,7 @@ import line_cor
|
|
52 |
import altair as alt
|
53 |
#pytesseract.pytesseract.tesseract_cmd = r"./Tesseract-OCR/tesseract.exe"
|
54 |
from PIL import Image
|
55 |
-
|
56 |
-
#@st.cache_resource(experimental_allow_widgets=True)
|
57 |
-
@st.cache_data
|
58 |
def read_pdf(file):
|
59 |
# images=pdf2image.convert_from_path(file)
|
60 |
# # print(type(images))
|
@@ -88,9 +86,8 @@ def read_pdf(file):
|
|
88 |
# all_page_text += text + " " #page.extractText()
|
89 |
# return all_page_text
|
90 |
st.title("NLP APPLICATION")
|
91 |
-
|
92 |
#@st.cache_resource(experimental_allow_widgets=True)
|
93 |
-
@st.cache_data
|
94 |
def text_analyzer(my_text):
|
95 |
nlp = spacy.load('en_core_web_sm')
|
96 |
docx = nlp(my_text)
|
@@ -104,9 +101,8 @@ def load_models():
|
|
104 |
model = GPT2LMHeadModel.from_pretrained('gpt2-large')
|
105 |
return tokenizer, model
|
106 |
# Function For Extracting Entities
|
107 |
-
|
108 |
#@st.cache_resource(experimental_allow_widgets=True)
|
109 |
-
@st.chache_data
|
110 |
def entity_analyzer(my_text):
|
111 |
nlp = spacy.load('en_core_web_sm')
|
112 |
docx = nlp(my_text)
|
@@ -172,20 +168,16 @@ def main():
|
|
172 |
#img = cv2.imread("scholarly_text.jpg")
|
173 |
text = message
|
174 |
if st.checkbox("Show Named Entities English/Bangla"):
|
175 |
-
st.cache_data.clear()
|
176 |
entity_result = entity_analyzer(text)
|
177 |
st.json(entity_result)
|
178 |
|
179 |
if st.checkbox("Show Sentiment Analysis for English"):
|
180 |
-
st.cache_data.clear()
|
181 |
blob = TextBlob(text)
|
182 |
result_sentiment = blob.sentiment
|
183 |
st.success(result_sentiment)
|
184 |
if st.checkbox("Spell Corrections for English"):
|
185 |
-
st.cache_data.clear()
|
186 |
st.success(TextBlob(text).correct())
|
187 |
if st.checkbox("Text Generation"):
|
188 |
-
st.cache_data.clear()
|
189 |
tokenizer, model = load_models()
|
190 |
input_ids = tokenizer(text, return_tensors='pt').input_ids
|
191 |
st.text("Using Hugging Face Transformer, Contrastive Search ..")
|
@@ -200,7 +192,6 @@ def main():
|
|
200 |
# st.success(summary_result)
|
201 |
if st.checkbox("Mark to English Text Summarization!"):
|
202 |
#st.title("Summarize Your Text for English only!")
|
203 |
-
st.cache_data.clear()
|
204 |
tokenizer = AutoTokenizer.from_pretrained('t5-base')
|
205 |
model = AutoModelWithLMHead.from_pretrained('t5-base', return_dict=True)
|
206 |
#st.text("Using Google T5 Transformer ..")
|
@@ -212,7 +203,6 @@ def main():
|
|
212 |
summary = tokenizer.decode(summary_ids[0])
|
213 |
st.success(summary)
|
214 |
if st.button("refresh"):
|
215 |
-
st.cache_data.clear()
|
216 |
st.experimental_rerun()
|
217 |
if __name__ == '__main__':
|
218 |
main()
|
|
|
52 |
import altair as alt
|
53 |
#pytesseract.pytesseract.tesseract_cmd = r"./Tesseract-OCR/tesseract.exe"
|
54 |
from PIL import Image
|
55 |
+
@st.experimental_singleton
|
|
|
|
|
56 |
def read_pdf(file):
|
57 |
# images=pdf2image.convert_from_path(file)
|
58 |
# # print(type(images))
|
|
|
86 |
# all_page_text += text + " " #page.extractText()
|
87 |
# return all_page_text
|
88 |
st.title("NLP APPLICATION")
|
89 |
+
@st.experimental_singleton
|
90 |
#@st.cache_resource(experimental_allow_widgets=True)
|
|
|
91 |
def text_analyzer(my_text):
|
92 |
nlp = spacy.load('en_core_web_sm')
|
93 |
docx = nlp(my_text)
|
|
|
101 |
model = GPT2LMHeadModel.from_pretrained('gpt2-large')
|
102 |
return tokenizer, model
|
103 |
# Function For Extracting Entities
|
104 |
+
@st.experimental_singleton
|
105 |
#@st.cache_resource(experimental_allow_widgets=True)
|
|
|
106 |
def entity_analyzer(my_text):
|
107 |
nlp = spacy.load('en_core_web_sm')
|
108 |
docx = nlp(my_text)
|
|
|
168 |
#img = cv2.imread("scholarly_text.jpg")
|
169 |
text = message
|
170 |
if st.checkbox("Show Named Entities English/Bangla"):
|
|
|
171 |
entity_result = entity_analyzer(text)
|
172 |
st.json(entity_result)
|
173 |
|
174 |
if st.checkbox("Show Sentiment Analysis for English"):
|
|
|
175 |
blob = TextBlob(text)
|
176 |
result_sentiment = blob.sentiment
|
177 |
st.success(result_sentiment)
|
178 |
if st.checkbox("Spell Corrections for English"):
|
|
|
179 |
st.success(TextBlob(text).correct())
|
180 |
if st.checkbox("Text Generation"):
|
|
|
181 |
tokenizer, model = load_models()
|
182 |
input_ids = tokenizer(text, return_tensors='pt').input_ids
|
183 |
st.text("Using Hugging Face Transformer, Contrastive Search ..")
|
|
|
192 |
# st.success(summary_result)
|
193 |
if st.checkbox("Mark to English Text Summarization!"):
|
194 |
#st.title("Summarize Your Text for English only!")
|
|
|
195 |
tokenizer = AutoTokenizer.from_pretrained('t5-base')
|
196 |
model = AutoModelWithLMHead.from_pretrained('t5-base', return_dict=True)
|
197 |
#st.text("Using Google T5 Transformer ..")
|
|
|
203 |
summary = tokenizer.decode(summary_ids[0])
|
204 |
st.success(summary)
|
205 |
if st.button("refresh"):
|
|
|
206 |
st.experimental_rerun()
|
207 |
if __name__ == '__main__':
|
208 |
main()
|