-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
328 lines (270 loc) · 16.3 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# Create a new Python file, e.g., `app.py`, and import the required libraries:
import streamlit as st
import pandas as pd
import streamlit.components.v1 as html
import streamlit.components.v1 as components
import streamlit_option_menu
from streamlit_option_menu import option_menu
from nlp_task.chatBot import ai_assistant
from nlp_task.about_app import about
from nlp_task.sentiment_analysis import (
textsource_sentiment_analysis,
sentiment_analysis,
)
from nlp_task.context_indentify import (
textsource_classification_analysis,
context_analysis)
from nlp_task.language_detection_translation import (
langDetect,
langTranslate)
from nlp_task.contact_info_extraction import extractInfo
from visualize import visualize
from nlp_task.recommendation import (
textsource_recommendation_analysis,
recommend)
from nlp_task.summarizer import (
summarize , textsource_summarize_analysis
)
from home import home
st.set_page_config(
page_title="Culture Flow",
page_icon="bi-braces-asterisk",
layout="wide",
)
st.markdown(
"""
<style>
# .css-nqowgj.edgvbvh3{
# visibility: hidden;
# }
.css-164nlkn.egzxvld1
{
visibility: hidden;
}
.css-1n543e5.edgvbvh10
{
background-color: #f5f5f5;
color: #000000;
border-radius: 0.25rem;
padding: 0.5rem 0.75rem;
transition-duration: 0.2s;
}
.css-1n543e5.edgvbvh10:hover {
background-color: blue;
color: white;
border:none;
}
</style>
""",
unsafe_allow_html=True,
)
# declare global variables:
sentiment_result = ""
text_data = ""
# Add the navigation sidebar and menu items:
def main_nav():
global sentiment_result , summarize_result , text_data , recommend_result , context_result , langDetect_result , langTranslate_result , extractInfo_result
with st.sidebar:
menu = option_menu(
menu_title="CultureFlow",
options=[
"Home",
"CultureFlow AI Chatbot",
"Perform NLP Analysis",
"Visualization Dashboard",
"Contact Us",
],
icons=["house", "book", "list-task", "activity","send"],
menu_icon="app-indicator",
default_index=0,
styles={
"container": {"padding": "5!important"},
"nav-link": {
"font-size": "16px",
"text-align": "left",
"margin": "0px",
"--hover-color": "#eee",
},
},
)
# Create the Home page with file upload functionality:
if menu == "Home":
home()
# Create the Educate Yourself page:
elif menu == "CultureFlow AI Chatbot":
ai_assistant()
# Create the Perform Analysis page with a dropdown for NLP tasks:
elif menu == "Perform NLP Analysis":
st.title("Perform NLP Analysis")
st.write("Upload your textual source file below:")
uploaded_file = st.file_uploader(
"Choose a file", type=["pdf", "txt", "csv", "xlsx"]
)
if uploaded_file is not None:
if uploaded_file.type == "pdf":
text_data = uploaded_file.read().decode("utf-8")
if uploaded_file.type == "text/plain":
text_data = uploaded_file.read().decode("utf-8")
elif uploaded_file.type == "application/vnd.ms-excel":
text_data = pd.read_csv(uploaded_file)
elif (
uploaded_file.type
== "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
):
text_data = pd.read_excel(uploaded_file)
st.success("File uploaded successfully!")
nlp_task = st.selectbox(
"Choose an task to perform",
[
"Sentiment Analysis",
"Language Detection & Translation",
"Actionable Recommendations",
"Text Classification and Context Identification",
"Contact Information Extraction",
"Summarize Your Data",
],
help= "Choose an NLP task to perform",
)
# sentiment analysis
if nlp_task == "Sentiment Analysis":
st.subheader("Sentiment Analysis on Textual Source")
if st.button("Perform Sentiment Analysis"):
sentiment_result = textsource_sentiment_analysis(text_data)
if sentiment_result != "":
st.write(sentiment_result)
else:
st.error("Please upload a file first!")
st.subheader("Perform Sentiment Analysis on Text Data")
sentiment_analysis()
# language detection and translation
elif nlp_task == "Language Detection & Translation":
Languages = {'afrikaans':'af','albanian':'sq','amharic':'am','arabic':'ar','armenian':'hy','azerbaijani':'az','basque':'eu','belarusian':'be','bengali':'bn','bosnian':'bs','bulgarian':'bg','catalan':'ca','cebuano':'ceb','chichewa':'ny','chinese (simplified)':'zh-cn','chinese (traditional)':'zh-tw','corsican':'co','croatian':'hr','czech':'cs','danish':'da','dutch':'nl','english':'en','esperanto':'eo','estonian':'et','filipino':'tl','finnish':'fi','french':'fr','frisian':'fy','galician':'gl','georgian':'ka','german':'de','greek':'el','gujarati':'gu','haitian creole':'ht','hausa':'ha','hawaiian':'haw','hebrew':'iw','hebrew':'he','hindi':'hi','hmong':'hmn','hungarian':'hu','icelandic':'is','igbo':'ig','indonesian':'id','irish':'ga','italian':'it','japanese':'ja','javanese':'jw','kannada':'kn','kazakh':'kk','khmer':'km','korean':'ko','kurdish (kurmanji)':'ku','kyrgyz':'ky','lao':'lo','latin':'la','latvian':'lv','lithuanian':'lt','luxembourgish':'lb','macedonian':'mk','malagasy':'mg','malay':'ms','malayalam':'ml','maltese':'mt','maori':'mi','marathi':'mr','mongolian':'mn','myanmar (burmese)':'my','nepali':'ne','norwegian':'no','odia':'or','pashto':'ps','persian':'fa','polish':'pl','portuguese':'pt','punjabi':'pa','romanian':'ro','russian':'ru','samoan':'sm','scots gaelic':'gd','serbian':'sr','sesotho':'st','shona':'sn','sindhi':'sd','sinhala':'si','slovak':'sk','slovenian':'sl','somali':'so','spanish':'es','sundanese':'su','swahili':'sw','swedish':'sv','tajik':'tg','tamil':'ta','telugu':'te','thai':'th','turkish':'tr','turkmen':'tk','ukrainian':'uk','urdu':'ur','uyghur':'ug','uzbek':'uz','vietnamese':'vi','welsh':'cy','xhosa':'xh','yiddish':'yi','yoruba':'yo','zulu':'zu'}
st.subheader("Language Detection & Translation on Textual Source")
if st.button("Detect Language"):
detection_result = langDetect(text_data)
if detection_result != "":
st.write(detection_result)
option0 = st.selectbox('Output language',
('malayalam', 'afrikaans', 'albanian', 'amharic', 'arabic', 'armenian', 'azerbaijani', 'basque', 'belarusian', 'bengali', 'bosnian', 'bulgarian', 'catalan', 'cebuano', 'chichewa', 'chinese (simplified)', 'chinese (traditional)', 'corsican', 'croatian', 'czech', 'danish', 'dutch', 'english', 'esperanto', 'estonian', 'filipino', 'finnish', 'french', 'frisian', 'galician', 'georgian', 'german', 'greek', 'gujarati', 'haitian creole', 'hausa', 'hawaiian', 'hebrew', 'hindi', 'hmong', 'hungarian', 'icelandic', 'igbo', 'indonesian', 'irish', 'italian', 'japanese', 'javanese', 'kannada', 'kazakh', 'khmer', 'korean', 'kurdish (kurmanji)', 'kyrgyz', 'lao', 'latin', 'latvian', 'lithuanian', 'luxembourgish', 'macedonian', 'malagasy', 'malay', 'maltese', 'maori', 'marathi', 'mongolian', 'myanmar (burmese)', 'nepali', 'norwegian', 'odia', 'pashto', 'persian', 'polish', 'portuguese', 'punjabi', 'romanian', 'russian', 'samoan', 'scots gaelic', 'serbian', 'sesotho', 'shona', 'sindhi', 'sinhala', 'slovak', 'slovenian', 'somali', 'spanish', 'sundanese', 'swahili', 'swedish', 'tajik', 'tamil', 'telugu', 'thai', 'turkish', 'turkmen', 'ukrainian', 'urdu', 'uyghur', 'uzbek', 'vietnamese', 'welsh', 'xhosa', 'yiddish', 'yoruba', 'zulu'))
value0 = Languages[option0]
if st.button("Translate"):
translation_result = langTranslate(detection_result,value0,text_data)
st.write(translation_result)
else:
st.error("Please upload a file first!")
st.subheader("Language Detection & Translation on Custom Text Input")
text = st.text_area("Enter text:",height=None,max_chars=None,key=None,help="Enter your text here")
option1 = st.selectbox('Input language',
('english', 'afrikaans', 'albanian', 'amharic', 'arabic', 'armenian', 'azerbaijani', 'basque', 'belarusian', 'bengali', 'bosnian', 'bulgarian', 'catalan', 'cebuano', 'chichewa', 'chinese (simplified)', 'chinese (traditional)', 'corsican', 'croatian', 'czech', 'danish', 'dutch', 'esperanto', 'estonian', 'filipino', 'finnish', 'french', 'frisian', 'galician', 'georgian', 'german', 'greek', 'gujarati', 'haitian creole', 'hausa', 'hawaiian', 'hebrew', 'hindi', 'hmong', 'hungarian', 'icelandic', 'igbo', 'indonesian', 'irish', 'italian', 'japanese', 'javanese', 'kannada', 'kazakh', 'khmer', 'korean', 'kurdish (kurmanji)', 'kyrgyz', 'lao', 'latin', 'latvian', 'lithuanian', 'luxembourgish', 'macedonian', 'malagasy', 'malay', 'malayalam', 'maltese', 'maori', 'marathi', 'mongolian', 'myanmar (burmese)', 'nepali', 'norwegian', 'odia', 'pashto', 'persian', 'polish', 'portuguese', 'punjabi', 'romanian', 'russian', 'samoan', 'scots gaelic', 'serbian', 'sesotho', 'shona', 'sindhi', 'sinhala', 'slovak', 'slovenian', 'somali', 'spanish', 'sundanese', 'swahili', 'swedish', 'tajik', 'tamil', 'telugu', 'thai', 'turkish', 'turkmen', 'ukrainian', 'urdu', 'uyghur', 'uzbek', 'vietnamese', 'welsh', 'xhosa', 'yiddish', 'yoruba', 'zulu') ,
key='input_lang')
option2 = st.selectbox('Output language',
('malayalam', 'afrikaans', 'albanian', 'amharic', 'arabic', 'armenian', 'azerbaijani', 'basque', 'belarusian', 'bengali', 'bosnian', 'bulgarian', 'catalan', 'cebuano', 'chichewa', 'chinese (simplified)', 'chinese (traditional)', 'corsican', 'croatian', 'czech', 'danish', 'dutch', 'english', 'esperanto', 'estonian', 'filipino', 'finnish', 'french', 'frisian', 'galician', 'georgian', 'german', 'greek', 'gujarati', 'haitian creole', 'hausa', 'hawaiian', 'hebrew', 'hindi', 'hmong', 'hungarian', 'icelandic', 'igbo', 'indonesian', 'irish', 'italian', 'japanese', 'javanese', 'kannada', 'kazakh', 'khmer', 'korean', 'kurdish (kurmanji)', 'kyrgyz', 'lao', 'latin', 'latvian', 'lithuanian', 'luxembourgish', 'macedonian', 'malagasy', 'malay', 'maltese', 'maori', 'marathi', 'mongolian', 'myanmar (burmese)', 'nepali', 'norwegian', 'odia', 'pashto', 'persian', 'polish', 'portuguese', 'punjabi', 'romanian', 'russian', 'samoan', 'scots gaelic', 'serbian', 'sesotho', 'shona', 'sindhi', 'sinhala', 'slovak', 'slovenian', 'somali', 'spanish', 'sundanese', 'swahili', 'swedish', 'tajik', 'tamil', 'telugu', 'thai', 'turkish', 'turkmen', 'ukrainian', 'urdu', 'uyghur', 'uzbek', 'vietnamese', 'welsh', 'xhosa', 'yiddish', 'yoruba', 'zulu') , key='output_lang')
value1 = Languages[option1]
value2 = Languages[option2]
if st.button('Translate Sentence'):
if text == "":
st.warning('Please **enter text** for translation')
else:
response = langTranslate(value1,value2,text)
st.write(response)
elif nlp_task == "Actionable Recommendations":
# st.write("Performing Actionable Recommendations...")
st.subheader("Actionable Recommendations on Textual Source")
st.info("Get actionable recommendations by our NLP based AI model in order to improve your company culture.")
if st.button("Perform Analysis"):
recommend_result = textsource_recommendation_analysis(text_data)
if recommend_result != "":
st.write(recommend_result)
else:
st.error("Please upload a file first!")
# recommend()
elif nlp_task == "Text Classification and Context Identification":
st.subheader("Contextual Topic Identification on Textual Source")
if st.button("Analyse"):
context_result = textsource_classification_analysis(text_data)
if context_result != "":
st.write(context_result)
else:
st.error("Please upload a file first!")
st.subheader("Perform Contextual Topic Analysis on Text Data")
context_analysis()
elif nlp_task == "Contact Information Extraction":
st.subheader("Extract Contact Infromation from Textual Source")
if st.button("Extract"):
extractInfo(text_data)
elif nlp_task == "Summarize Your Data":
st.subheader("Text Summarization on Textual Source")
if st.button("Perform Text Summarization"):
summarize_result = textsource_summarize_analysis(text_data)
if summarize_result != "":
st.write(summarize_result)
else:
st.error("Please upload a file first!")
summarize ()
# Create the Visualization Dashboard page:
elif menu == "Visualization Dashboard":
visualize()
# Create the Contact Us page:
elif menu == "Contact Us":
st.title("Contact Us")
st.markdown(
""" <style> .font {
font-size:25px ; font-family: 'Helvetica'; color: 'blue';}
</style> """,
unsafe_allow_html=True,
)
st.markdown(
'<p class="font">Please help us improve. Your valuable feedbacks matter!</p>',
unsafe_allow_html=True,
)
with st.form(
key="columns_in_form2", clear_on_submit=True
): # set clear_on_submit=True so that the form will be reset/cleared once it's submitted
# st.write('Please help us improve!')
Name = st.text_input(label="Enter Your Name") # Collect user feedback
Email = st.text_input(label="Enter Email") # Collect user feedback
Message = st.text_input(
label="SHare Your Vews and Feedback!"
) # Collect user feedback
submitted = st.form_submit_button("Submit")
if submitted:
st.write(
"Thanks for your contacting us. We will respond to your questions or inquiries as soon as possible!"
)
with st.sidebar:
st.error("The web app is under continuous development.Please check out our [Github repository](https://github.com/AbhishekRP2002/CultureFlow) for more details.")
# footer="""<style>
# a:link , a:visited{
# color: white;
# background-color: transparent;
# text-decoration: none;
# }
# a:hover, a:active {
# color: blue;
# background-color: transparent;
# text-decoration: bold;
# }
# .footer {
# position: fixed;
# left: 0;
# bottom: 0;
# width: 100%;
# background-color: #FF4B4B;
# color: black;
# display: flex;
# flex-direction: row;
# align-items: center;
# text-align: center;
# justify-content: center;
# height: 50px;
# color: white;
# }
# </style>
# <div class="footer">
# <p>Developed with ❤ by <a href="https://github.com/Siddhanthota" target="_blank">Team Alpha</a></p>
# </div>
# """
# st.markdown(footer,unsafe_allow_html=True)
# Run the app:
if __name__ == "__main__":
main_nav()