Task-273 Reworked the UI
Browse files
app.py
CHANGED
@@ -1,9 +1,27 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
from annotated_text import annotated_text, annotation
|
3 |
import time
|
4 |
from random import randint, uniform
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def output_results(res):
|
9 |
label_dict = {
|
@@ -13,10 +31,11 @@ def output_results(res):
|
|
13 |
'Disability': '#8B5E3C',
|
14 |
'Religion': '#A347BA',
|
15 |
'Unspecified': '#A0A0A0'
|
16 |
-
|
17 |
}
|
|
|
18 |
with rc:
|
19 |
-
|
|
|
20 |
at_list = []
|
21 |
if res['numerical_sentiment'] == 1:
|
22 |
# st.markdown('##### Category Results:')
|
@@ -64,13 +83,36 @@ def analyze_text(text):
|
|
64 |
|
65 |
if res is not None:
|
66 |
st.session_state.results.append(res)
|
|
|
67 |
output_results(res)
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
st.markdown(
|
75 |
"""The NLPinitiative Discriminatory Text Classifier is an advanced
|
76 |
natural language processing tool designed to detect and flag potentially
|
@@ -80,19 +122,4 @@ with pri_container.expander('About This Application'):
|
|
80 |
assess it based on linguistic patterns and context. While the tool provides
|
81 |
valuable insights, we encourage users to review flagged content thoughtfully
|
82 |
and consider context when interpreting results."""
|
83 |
-
)
|
84 |
-
|
85 |
-
st.divider()
|
86 |
-
|
87 |
-
chat_container = st.container()
|
88 |
-
rc = chat_container.container(height=500)
|
89 |
-
|
90 |
-
if "results" not in st.session_state:
|
91 |
-
st.session_state.results = []
|
92 |
-
|
93 |
-
with rc:
|
94 |
-
for result in st.session_state.results:
|
95 |
-
output_results(result)
|
96 |
-
|
97 |
-
if entry := chat_container.chat_input('Enter text to classify'):
|
98 |
-
analyze_text(entry)
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
from annotated_text import annotated_text, annotation
|
4 |
import time
|
5 |
from random import randint, uniform
|
6 |
|
7 |
+
history_df = pd.DataFrame(data=[], columns=['Text', 'Classification', 'Gender', 'Race', 'Sexuality', 'Disability', 'Religion', 'Unspecified'])
|
8 |
+
|
9 |
+
def extract_data(json_obj):
|
10 |
+
row_data = []
|
11 |
+
|
12 |
+
row_data.append(json_obj['raw_text'])
|
13 |
+
row_data.append(json_obj['text_sentiment'])
|
14 |
+
cat_dict = json_obj['category_sentiments']
|
15 |
+
for cat in cat_dict.keys():
|
16 |
+
raw_val = cat_dict[cat]
|
17 |
+
val = f'{raw_val * 100: .2f}%' if raw_val is not None else 'N/A'
|
18 |
+
row_data.append(val)
|
19 |
+
|
20 |
+
return row_data
|
21 |
+
|
22 |
+
def load_history():
|
23 |
+
for result in st.session_state.results:
|
24 |
+
history_df.loc[len(history_df)] = extract_data(result)
|
25 |
|
26 |
def output_results(res):
|
27 |
label_dict = {
|
|
|
31 |
'Disability': '#8B5E3C',
|
32 |
'Religion': '#A347BA',
|
33 |
'Unspecified': '#A0A0A0'
|
|
|
34 |
}
|
35 |
+
|
36 |
with rc:
|
37 |
+
st.markdown('### Results')
|
38 |
+
with st.container(border=True):
|
39 |
at_list = []
|
40 |
if res['numerical_sentiment'] == 1:
|
41 |
# st.markdown('##### Category Results:')
|
|
|
83 |
|
84 |
if res is not None:
|
85 |
st.session_state.results.append(res)
|
86 |
+
history_df.loc[-1] = extract_data(res)
|
87 |
output_results(res)
|
88 |
|
89 |
+
st.title('NLPinitiative Text Classifier')
|
90 |
+
tab1, tab2 = st.tabs(['Classifier', 'About This App'])
|
91 |
+
|
92 |
+
if "results" not in st.session_state:
|
93 |
+
st.session_state.results = []
|
94 |
+
|
95 |
+
load_history()
|
96 |
+
|
97 |
+
with tab1:
|
98 |
+
"Text Classifier for determining if entered text is discriminatory (and the categories of discrimination) or Non-Discriminatory."
|
99 |
+
|
100 |
+
with st.container():
|
101 |
+
with st.expander('History'):
|
102 |
+
st.write(history_df)
|
103 |
+
|
104 |
+
rc = st.container()
|
105 |
|
106 |
+
text_form = st.form(key='classifier', clear_on_submit=True, enter_to_submit=True)
|
107 |
+
with text_form:
|
108 |
+
text_area = st.text_area('Enter text to classify')
|
109 |
+
form_btn = st.form_submit_button('submit')
|
110 |
+
|
111 |
+
if entry := text_area:
|
112 |
+
analyze_text(entry)
|
113 |
+
|
114 |
+
|
115 |
+
with tab2:
|
116 |
st.markdown(
|
117 |
"""The NLPinitiative Discriminatory Text Classifier is an advanced
|
118 |
natural language processing tool designed to detect and flag potentially
|
|
|
122 |
assess it based on linguistic patterns and context. While the tool provides
|
123 |
valuable insights, we encourage users to review flagged content thoughtfully
|
124 |
and consider context when interpreting results."""
|
125 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|