Ridealist commited on
Commit
b487efe
1 Parent(s): 7ede674

feat: add field validation and show warning message

Browse files
Files changed (1) hide show
  1. vocal_app.py +49 -21
vocal_app.py CHANGED
@@ -265,38 +265,63 @@ def page3():
265
  st.write("2. Select a topic")
266
  st.session_state.topic = st.selectbox("Choose your topic", topic_list)
267
 
268
- st.write("3. Write 3 cases here (Each case should be consisted of opinion, reasoning, and example).")
269
- st.session_state.case1 = st.text_area(
 
270
  label="Case 1",
271
  placeholder="Each case should be consisted of opinion, reasoning, and example.",
272
  height=100
273
  )
274
- st.session_state.case2 = st.text_area(
275
  label="Case 2",
276
  placeholder="Each case should be consisted of opinion, reasoning, and example.",
277
  height=100
278
- )
279
- st.session_state.case3 = st.text_area(
280
  label="Case 3",
281
  placeholder="Each case should be consisted of opinion, reasoning, and example.",
282
  height=100
283
- )
284
-
285
  st.session_state.pros_and_cons = st.selectbox("Choose your Side (Pros and Cons)", ["Pros", "Cons"])
286
 
287
- st.button(
288
- "Start Debate",
289
- on_click=page4_controller
290
- )
291
-
 
 
 
 
 
 
 
 
 
292
 
293
  with st.sidebar:
294
  st.sidebar.title('Ask to GPT')
295
- st.sidebar.text_area(
296
- label="Input text here",
297
  placeholder="Input text here",
298
  height=100)
299
- st.sidebar.button("Ask")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
 
301
  #########################################################
302
  # Page4
@@ -317,18 +342,23 @@ def page4():
317
  with st.sidebar:
318
  st.sidebar.title('Ask to GPT')
319
  user_input = st.sidebar.text_area(
320
- label="Input text here",
321
  placeholder="Input text here",
322
  height=100)
323
  output = st.sidebar.button("Ask")
 
324
  if output:
325
- result = gpt_call(user_input)
 
 
 
 
326
  else:
327
  result = ""
328
 
329
  st.sidebar.text_area(
330
- label="Answer in here",
331
- placeholder="(Answer)",
332
  value=result,
333
  height=150)
334
 
@@ -356,8 +386,6 @@ def page4():
356
  container = st.container()
357
 
358
  with container:
359
- #TODO (웅기형) : STT 붙이는 부분
360
-
361
  with st.form(key='my_form', clear_on_submit=True):
362
  audio = audiorecorder("Click to record", "Recording...")
363
 
 
265
  st.write("2. Select a topic")
266
  st.session_state.topic = st.selectbox("Choose your topic", topic_list)
267
 
268
+ st.write("3. Write 3 cases")
269
+
270
+ case1 = st.text_area(
271
  label="Case 1",
272
  placeholder="Each case should be consisted of opinion, reasoning, and example.",
273
  height=100
274
  )
275
+ case2 = st.text_area(
276
  label="Case 2",
277
  placeholder="Each case should be consisted of opinion, reasoning, and example.",
278
  height=100
279
+ )
280
+ case3 = st.text_area(
281
  label="Case 3",
282
  placeholder="Each case should be consisted of opinion, reasoning, and example.",
283
  height=100
284
+ )
285
+ case_error_message = st.empty()
286
  st.session_state.pros_and_cons = st.selectbox("Choose your Side (Pros and Cons)", ["Pros", "Cons"])
287
 
288
+ start = st.button(label="Start Debate")
289
+
290
+ def validate_case(error_message):
291
+ if not case1 or not case2 or not case3:
292
+ case_error_message.error("Please enter above all", icon="🚨")
293
+ else:
294
+ st.session_state.case1 = case1
295
+ st.session_state.case2 = case2
296
+ st.session_state.case3 = case3
297
+ page4_controller()
298
+
299
+ if start:
300
+ validate_case(case_error_message)
301
+
302
 
303
  with st.sidebar:
304
  st.sidebar.title('Ask to GPT')
305
+ user_input = st.sidebar.text_area(
306
+ label="Question",
307
  placeholder="Input text here",
308
  height=100)
309
+ output = st.sidebar.button("Ask")
310
+ input_error_message = st.empty()
311
+ if output:
312
+ if not user_input:
313
+ input_error_message.error("Please enter your question")
314
+ result = ""
315
+ else:
316
+ result = gpt_call(user_input)
317
+ else:
318
+ result = ""
319
+
320
+ st.sidebar.text_area(
321
+ label="Answer",
322
+ placeholder="(Answer will be shown here)",
323
+ value=result,
324
+ height=150)
325
 
326
  #########################################################
327
  # Page4
 
342
  with st.sidebar:
343
  st.sidebar.title('Ask to GPT')
344
  user_input = st.sidebar.text_area(
345
+ label="Question",
346
  placeholder="Input text here",
347
  height=100)
348
  output = st.sidebar.button("Ask")
349
+ input_error_message = st.empty()
350
  if output:
351
+ if not user_input:
352
+ input_error_message.error("Please enter your question")
353
+ result = ""
354
+ else:
355
+ result = gpt_call(user_input)
356
  else:
357
  result = ""
358
 
359
  st.sidebar.text_area(
360
+ label="Answer",
361
+ placeholder="(Answer will be shown here)",
362
  value=result,
363
  height=150)
364
 
 
386
  container = st.container()
387
 
388
  with container:
 
 
389
  with st.form(key='my_form', clear_on_submit=True):
390
  audio = audiorecorder("Click to record", "Recording...")
391