Ridealist commited on
Commit
9fdfed4
β€’
1 Parent(s): 7d16d28

bugfix: adjust button width for container width & button highliting

Browse files
Files changed (2) hide show
  1. app.py +28 -43
  2. modules/whisper_modules.py +3 -3
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import streamlit as st
2
  import numpy as np
3
- import openai
4
  import pprint
5
  from decimal import Decimal
6
 
@@ -8,29 +7,17 @@ from gtts import gTTS
8
  from collections import Counter
9
  from streamlit_chat import message
10
 
11
- # db_modules
12
- from modules.db_modules import get_db, put_item, get_item, get_lastest_item
13
-
14
- from dotenv import dotenv_values
15
  from bots.judgement_bot import debate_judgement
16
- from collections import Counter
17
  import time
18
  from time import strftime
19
 
20
  from audiorecorder import audiorecorder
21
 
22
  # modules
 
23
  from modules.gpt_modules import gpt_call, gpt_call_context
24
- #from modules.whisper_modules import transcribe
25
-
26
- config = dotenv_values(".env")
27
 
28
- openai.organization = config.get('OPENAI_ORGANIZATION')
29
- openai.api_key = config.get('OPENAI_API_KEY')
30
-
31
-
32
- #openai.organization = st.secrets['OPENAI_ORGANIZATION']
33
- #openai.api_key = st.secrets['OPENAI_API_KEY']
34
 
35
  #########################################################
36
  # GET DB
@@ -117,7 +104,7 @@ def save_info(user_id):
117
  print("User ID:", user_id)
118
 
119
  # Session state
120
- #session_state = SessionState.get(user_id="", openAI_token="", debate_theme="")
121
  def write_info():
122
  st.write('You choose', st.session_state.topic_list)
123
 
@@ -128,11 +115,8 @@ def page_1_2_controller():
128
  st.warning('Please fill in all the required fields.')
129
  else:
130
  st.session_state.page = "Page 2"
131
- print("save info")
132
-
133
  save_info(st.session_state.user_id)
134
 
135
-
136
  #########################################################
137
  # Session Update
138
  #########################################################
@@ -177,21 +161,23 @@ def page_n_1_controller():
177
  # Page 1
178
  #########################################################
179
  def page1():
180
- _, _, pre, home = st.columns([5, 5, 1, 1])
181
  with home:
182
- st.button("πŸ”", on_click=page_n_1_controller)
183
 
184
  st.header('User Info')
185
  st.session_state.user_id = st.text_input(
186
- label="User ID",
 
187
  max_chars=100,
188
- placeholder="Enter user ID"
189
- )
190
 
191
  st.button(
192
  label='Next',
 
193
  on_click=page_1_2_controller
194
- )
195
 
196
  #########################################################
197
  # Page 2
@@ -199,9 +185,9 @@ def page1():
199
  def page2():
200
  _, _, pre, home = st.columns([5, 5, 1, 1])
201
  with pre:
202
- st.button("πŸ”™", on_click=page_n_1_controller)
203
  with home:
204
- st.button("πŸ”", on_click=page_n_1_controller)
205
 
206
  st.header("Choose Option")
207
  option_result = st.selectbox("Choose your option", ["Total Debate", "Evaluation Only & Analyzing Utterances"])
@@ -214,6 +200,7 @@ def page2():
214
 
215
  st.button(
216
  label='Next',
 
217
  on_click=page_control_func
218
  )
219
 
@@ -237,13 +224,14 @@ def page3():
237
 
238
  _, _, pre, home = st.columns([5, 5, 1, 1])
239
  with pre:
240
- st.button("πŸ”™", on_click=page_1_2_controller)
241
  with home:
242
- st.button("πŸ”", on_click=page_n_1_controller)
243
  st.header("Debate History")
244
 
245
  st.button(
246
  label=f'πŸš€ Start new debate',
 
247
  on_click=page_3_4_controller
248
  )
249
  st.write("_"*50)
@@ -275,9 +263,9 @@ def page4():
275
 
276
  _, _, pre, home = st.columns([5, 5, 1, 1])
277
  with pre:
278
- st.button("πŸ”™", on_click=page_2_3_controller)
279
  with home:
280
- st.button("πŸ”", on_click=page_n_1_controller)
281
 
282
  st.header("Total Debate")
283
  debate_themes = ['Education','Sports','Religion','Justice','Pandemic','Politics','Minority','etc']
@@ -473,15 +461,13 @@ def execute_stt(audio, error_message):
473
  wav_file = open("audio/audio.wav", "wb")
474
  wav_file.write(audio.tobytes())
475
  wav_file.close()
476
-
477
- audio_file= open("audio/audio.wav", "rb")
478
  try:
479
- user_input = openai.Audio.transcribe("whisper-1", audio_file).text
480
  except:
481
  error_message.error("Whisper Error : The engine is currently overloaded, it will be auto-reloaded in a second")
482
  time.sleep(1)
483
  st.experimental_rerun()
484
- audio_file.close()
485
  return user_input
486
 
487
  def page5():
@@ -568,9 +554,9 @@ def page5():
568
 
569
  _, _, pre, home = st.columns([5, 5, 1, 1])
570
  with pre:
571
- st.button("πŸ”™", on_click=page_3_4_controller)
572
  with home:
573
- st.button("πŸ”", on_click=page_n_1_controller)
574
 
575
  # container for chat history
576
  response_container = st.container()
@@ -628,11 +614,9 @@ def page5():
628
  'turn_num': turn_num,
629
  }
630
  )
631
-
632
  else:
633
  send_error_message.error("Please record your voice first", icon="🚨")
634
  reload = True
635
- print("Nothing to transcribe")
636
 
637
  with response_container:
638
  message(st.session_state['bot_debate_history'][0], key='0_bot')
@@ -657,6 +641,7 @@ def page5():
657
 
658
  st.button(
659
  label="Next",
 
660
  on_click=page_5_6_controller
661
  )
662
 
@@ -675,9 +660,9 @@ def page6():
675
 
676
  _, _, pre, home = st.columns([5, 5, 1, 1])
677
  with pre:
678
- st.button("πŸ”™", on_click=page_4_5_controller)
679
  with home:
680
- st.button("πŸ”", on_click=page_n_1_controller)
681
 
682
  # st.tab
683
  st.header('Total Debate Evaluation')
@@ -797,9 +782,9 @@ def page7():
797
 
798
  _, _, pre, home = st.columns([5, 5, 1, 1])
799
  with pre:
800
- st.button("πŸ”™", on_click=page_1_2_controller)
801
  with home:
802
- st.button("πŸ”", on_click=page_n_1_controller)
803
 
804
  st.header('Total Debate Evaluation')
805
 
 
1
  import streamlit as st
2
  import numpy as np
 
3
  import pprint
4
  from decimal import Decimal
5
 
 
7
  from collections import Counter
8
  from streamlit_chat import message
9
 
 
 
 
 
10
  from bots.judgement_bot import debate_judgement
 
11
  import time
12
  from time import strftime
13
 
14
  from audiorecorder import audiorecorder
15
 
16
  # modules
17
+ from modules.db_modules import get_db, put_item, get_item, get_lastest_item
18
  from modules.gpt_modules import gpt_call, gpt_call_context
19
+ from modules.whisper_modules import whisper_transcribe
 
 
20
 
 
 
 
 
 
 
21
 
22
  #########################################################
23
  # GET DB
 
104
  print("User ID:", user_id)
105
 
106
  # Session state
107
+ # session_state = SessionState.get(user_id="", openAI_token="", debate_theme="")
108
  def write_info():
109
  st.write('You choose', st.session_state.topic_list)
110
 
 
115
  st.warning('Please fill in all the required fields.')
116
  else:
117
  st.session_state.page = "Page 2"
 
 
118
  save_info(st.session_state.user_id)
119
 
 
120
  #########################################################
121
  # Session Update
122
  #########################################################
 
161
  # Page 1
162
  #########################################################
163
  def page1():
164
+ _, _, _, home = st.columns([5, 5, 1, 1])
165
  with home:
166
+ st.button("πŸ”", on_click=page_n_1_controller, use_container_width=True)
167
 
168
  st.header('User Info')
169
  st.session_state.user_id = st.text_input(
170
+ label='User ID',
171
+ # key='user_id',
172
  max_chars=100,
173
+ placeholder="Enter user ID",
174
+ )
175
 
176
  st.button(
177
  label='Next',
178
+ type='primary',
179
  on_click=page_1_2_controller
180
+ )
181
 
182
  #########################################################
183
  # Page 2
 
185
  def page2():
186
  _, _, pre, home = st.columns([5, 5, 1, 1])
187
  with pre:
188
+ st.button("πŸ”™", on_click=page_n_1_controller, use_container_width=True)
189
  with home:
190
+ st.button("πŸ”", on_click=page_n_1_controller, use_container_width=True)
191
 
192
  st.header("Choose Option")
193
  option_result = st.selectbox("Choose your option", ["Total Debate", "Evaluation Only & Analyzing Utterances"])
 
200
 
201
  st.button(
202
  label='Next',
203
+ type='primary',
204
  on_click=page_control_func
205
  )
206
 
 
224
 
225
  _, _, pre, home = st.columns([5, 5, 1, 1])
226
  with pre:
227
+ st.button("πŸ”™", on_click=page_1_2_controller, use_container_width=True)
228
  with home:
229
+ st.button("πŸ”", on_click=page_n_1_controller, use_container_width=True)
230
  st.header("Debate History")
231
 
232
  st.button(
233
  label=f'πŸš€ Start new debate',
234
+ type='primary',
235
  on_click=page_3_4_controller
236
  )
237
  st.write("_"*50)
 
263
 
264
  _, _, pre, home = st.columns([5, 5, 1, 1])
265
  with pre:
266
+ st.button("πŸ”™", on_click=page_2_3_controller, use_container_width=True)
267
  with home:
268
+ st.button("πŸ”", on_click=page_n_1_controller, use_container_width=True)
269
 
270
  st.header("Total Debate")
271
  debate_themes = ['Education','Sports','Religion','Justice','Pandemic','Politics','Minority','etc']
 
461
  wav_file = open("audio/audio.wav", "wb")
462
  wav_file.write(audio.tobytes())
463
  wav_file.close()
 
 
464
  try:
465
+ user_input = whisper_transcribe(audio)
466
  except:
467
  error_message.error("Whisper Error : The engine is currently overloaded, it will be auto-reloaded in a second")
468
  time.sleep(1)
469
  st.experimental_rerun()
470
+
471
  return user_input
472
 
473
  def page5():
 
554
 
555
  _, _, pre, home = st.columns([5, 5, 1, 1])
556
  with pre:
557
+ st.button("πŸ”™", on_click=page_3_4_controller, use_container_width=True)
558
  with home:
559
+ st.button("πŸ”", on_click=page_n_1_controller, use_container_width=True)
560
 
561
  # container for chat history
562
  response_container = st.container()
 
614
  'turn_num': turn_num,
615
  }
616
  )
 
617
  else:
618
  send_error_message.error("Please record your voice first", icon="🚨")
619
  reload = True
 
620
 
621
  with response_container:
622
  message(st.session_state['bot_debate_history'][0], key='0_bot')
 
641
 
642
  st.button(
643
  label="Next",
644
+ type="primary",
645
  on_click=page_5_6_controller
646
  )
647
 
 
660
 
661
  _, _, pre, home = st.columns([5, 5, 1, 1])
662
  with pre:
663
+ st.button("πŸ”™", on_click=page_4_5_controller, use_container_width=True)
664
  with home:
665
+ st.button("πŸ”", on_click=page_n_1_controller, use_container_width=True)
666
 
667
  # st.tab
668
  st.header('Total Debate Evaluation')
 
782
 
783
  _, _, pre, home = st.columns([5, 5, 1, 1])
784
  with pre:
785
+ st.button("πŸ”™", on_click=page_1_2_controller, use_container_width=True)
786
  with home:
787
+ st.button("πŸ”", on_click=page_n_1_controller, use_container_width=True)
788
 
789
  st.header('Total Debate Evaluation')
790
 
modules/whisper_modules.py CHANGED
@@ -62,11 +62,11 @@ def debate_in_sound(audio):
62
  return response
63
 
64
 
65
- def transcribe(audio):
66
-
67
- audio_file= open("./audio.mp3", "rb")
68
 
 
69
  result = openai.Audio.transcribe("whisper-1", audio_file).text
 
70
 
71
  return result
72
 
 
62
  return response
63
 
64
 
65
+ def whisper_transcribe(audio):
 
 
66
 
67
+ audio_file= open("audio/audio.wav", "rb")
68
  result = openai.Audio.transcribe("whisper-1", audio_file).text
69
+ audio_file.close()
70
 
71
  return result
72