diana3135 commited on
Commit
de26bd7
·
1 Parent(s): d6520c8

add word counter

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -140,6 +140,10 @@ def word_limit_validation(human_input):
140
  def on_textbox_change(session_index, session_manager, service, SHEET_ID):
141
  return save_data(session_index, session_manager, service, SHEET_ID)
142
 
 
 
 
 
143
  if __name__ == "__main__":
144
  api_key = get_api_key(local=False)
145
  service, SHEET_IDs = get_sheet_service(local=False)
@@ -187,6 +191,8 @@ if __name__ == "__main__":
187
  with group_a_content:
188
  with gr.Row():
189
  human_input = gr.Textbox(label="Human Input (At least 50 words)")
 
 
190
  with gr.Row():
191
  submit_btn = gr.Button("Create")
192
  with gr.Row():
@@ -238,6 +244,8 @@ if __name__ == "__main__":
238
  with gr.Row():
239
  initial_answer = gr.Textbox(label="AI Initial Answer")
240
  modification_suggestions = gr.Textbox(label="Refine AI output (At least 50 words)")
 
 
241
  with gr.Row():
242
  create_final_btn = gr.Button("Modify")
243
  with gr.Row():
@@ -296,7 +304,13 @@ if __name__ == "__main__":
296
 
297
  with group_c_content:
298
  with gr.Row():
299
- human_input = gr.Textbox(label="Human Input (At least 50 words)")
 
 
 
 
 
 
300
  with gr.Row():
301
  create_btn = gr.Button("Create")
302
  with gr.Row():
 
140
  def on_textbox_change(session_index, session_manager, service, SHEET_ID):
141
  return save_data(session_index, session_manager, service, SHEET_ID)
142
 
143
+ def update_word_count(text):
144
+ words = text.split()
145
+ return f"Word count: {len(words)}"
146
+
147
  if __name__ == "__main__":
148
  api_key = get_api_key(local=False)
149
  service, SHEET_IDs = get_sheet_service(local=False)
 
191
  with group_a_content:
192
  with gr.Row():
193
  human_input = gr.Textbox(label="Human Input (At least 50 words)")
194
+ word_count_display_a = gr.Label(value="Word count: 0")
195
+ human_input.change(fn=update_word_count, inputs=human_input, outputs=word_count_display_a)
196
  with gr.Row():
197
  submit_btn = gr.Button("Create")
198
  with gr.Row():
 
244
  with gr.Row():
245
  initial_answer = gr.Textbox(label="AI Initial Answer")
246
  modification_suggestions = gr.Textbox(label="Refine AI output (At least 50 words)")
247
+ word_count_display_b = gr.Label(value="Word count: 0")
248
+ modification_suggestions.change(fn=update_word_count, inputs=modification_suggestions, outputs=word_count_display_b)
249
  with gr.Row():
250
  create_final_btn = gr.Button("Modify")
251
  with gr.Row():
 
304
 
305
  with group_c_content:
306
  with gr.Row():
307
+ human_input = gr.Textbox(label="Human Input (At least 50 words)", elem_id="human_input")
308
+ word_count = gr.Label(value="Word count: 0", elem_id="word_count")
309
+ human_input.change(
310
+ fn=update_word_count,
311
+ inputs=human_input,
312
+ outputs=word_count
313
+ )
314
  with gr.Row():
315
  create_btn = gr.Button("Create")
316
  with gr.Row():