dlsmallw commited on
Commit
aa4fbce
·
1 Parent(s): a189dd1

Task-295 Fix how information is displayed to users

Browse files
Files changed (1) hide show
  1. app.py +12 -18
app.py CHANGED
@@ -6,12 +6,13 @@ from scripts.predict import InferenceHandler
6
 
7
  history_df = pd.DataFrame(data=[], columns=['Text', 'Classification', 'Gender', 'Race', 'Sexuality', 'Disability', 'Religion', 'Unspecified'])
8
  rc = None
9
- ih = None
10
- entry = None
11
 
12
  @st.cache_data
13
  def load_inference_handler(api_token):
14
- ih = InferenceHandler(api_token)
 
 
 
15
 
16
  def extract_data(json_obj):
17
  row_data = []
@@ -59,6 +60,7 @@ def output_results(res):
59
 
60
  @st.cache_data
61
  def analyze_text(text):
 
62
  if ih:
63
  res = None
64
  with rc:
@@ -80,13 +82,7 @@ API_KEY = st.sidebar.text_input(
80
  help="You can get your free API token in your settings page: https://huggingface.co/settings/tokens",
81
  type="password",
82
  )
83
-
84
- try:
85
- if API_KEY is not None and len(API_KEY) > 0:
86
- ih = InferenceHandler(API_KEY)
87
- except:
88
- ih = None
89
- st.error('Invalid Token')
90
 
91
  tab1, tab2 = st.tabs(['Classifier', 'About This App'])
92
 
@@ -100,21 +96,19 @@ with tab1:
100
 
101
  hist_container = st.container()
102
  hist_expander = hist_container.expander('History')
 
103
  rc = st.container()
104
-
105
  text_form = st.form(key='classifier', clear_on_submit=True, enter_to_submit=True)
106
  with text_form:
 
107
  text_area = st.text_area('Enter text to classify', value='', disabled=True if ih is None else False)
108
  form_btn = st.form_submit_button('submit', disabled=True if ih is None else False)
109
-
110
- if entry := text_area:
111
- st.write(f'TEXT AREA: {entry}')
112
- if entry and len(entry) > 0:
113
- analyze_text(entry)
114
- entry = None
115
 
116
  with hist_expander:
117
- st.dataframe(history_df)
 
118
 
119
  with tab2:
120
  st.markdown(
 
6
 
7
  history_df = pd.DataFrame(data=[], columns=['Text', 'Classification', 'Gender', 'Race', 'Sexuality', 'Disability', 'Religion', 'Unspecified'])
8
  rc = None
 
 
9
 
10
  @st.cache_data
11
  def load_inference_handler(api_token):
12
+ try:
13
+ return InferenceHandler(api_token)
14
+ except:
15
+ return None
16
 
17
  def extract_data(json_obj):
18
  row_data = []
 
60
 
61
  @st.cache_data
62
  def analyze_text(text):
63
+ st.write(f'Text: {text}')
64
  if ih:
65
  res = None
66
  with rc:
 
82
  help="You can get your free API token in your settings page: https://huggingface.co/settings/tokens",
83
  type="password",
84
  )
85
+ ih = load_inference_handler(API_KEY)
 
 
 
 
 
 
86
 
87
  tab1, tab2 = st.tabs(['Classifier', 'About This App'])
88
 
 
96
 
97
  hist_container = st.container()
98
  hist_expander = hist_container.expander('History')
99
+
100
  rc = st.container()
 
101
  text_form = st.form(key='classifier', clear_on_submit=True, enter_to_submit=True)
102
  with text_form:
103
+ entry = None
104
  text_area = st.text_area('Enter text to classify', value='', disabled=True if ih is None else False)
105
  form_btn = st.form_submit_button('submit', disabled=True if ih is None else False)
106
+ if form_btn and text_area is not None and len(text_area) > 0:
107
+ analyze_text(text_area)
 
 
 
 
108
 
109
  with hist_expander:
110
+ st.dataframe(history_df, hide_index=True)
111
+
112
 
113
  with tab2:
114
  st.markdown(