kkngan commited on
Commit
8628478
·
verified ·
1 Parent(s): 349e62e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -12,7 +12,7 @@ def callback():
12
  st.audio(audio_bytes)
13
 
14
  def transcribe_and_translate(upload):
15
- pipe = pipeline("automatic-speech-recognition", model="openai/whisper-medium")
16
  transcribe_result = pipe(upload, generate_kwargs={'task': 'transcribe'})
17
  translate_result = pipe(upload, generate_kwargs={'task': 'translate'})
18
  return transcribe_result['text'], translate_result['text']
@@ -82,19 +82,19 @@ def main():
82
  if options == "Start a recording":
83
  audio = mic_recorder(key='my_recorder', callback=callback)
84
  elif options == "Upload an audio":
85
- audio = st.file_uploader("Please upload an audio")
86
  else:
87
  text = st.text_area("Please input the transcript (Only support English)")
88
  button = st.button('Submit')
89
 
90
  if button:
91
- with st.spinner(text="Loading... It may take longer for initialisation."):
92
  model, tokenizer = load_model()
93
  if options == "Start a recording":
94
  transcibe_text, translate_text = transcribe_and_translate(upload=audio["bytes"])
95
  prediction, probability = predict(text=translate_text, model=model, tokenizer=tokenizer)
96
  elif options == "Upload an audio":
97
- transcibe_text, translate_text = transcribe_and_translate(upload=audio.getvalue)
98
  prediction, probability = predict(text=translate_text, model=model, tokenizer=tokenizer)
99
  else:
100
  transcibe_text = text
@@ -112,7 +112,7 @@ def main():
112
  # Convert probability to bar
113
  st.write(f'\n')
114
  objects = ('Hardware', 'Access', 'Miscellaneous', 'HR Support', 'Purchase', 'Administrative rights', 'Storage', 'Internal Project')
115
- df = pd.DataFrame({'Categories': objects, 'Probability': probability[0]})
116
  st.bar_chart(data=df, x='Categories', y='Probability')
117
 
118
  if __name__ == '__main__':
 
12
  st.audio(audio_bytes)
13
 
14
  def transcribe_and_translate(upload):
15
+ pipe = pipeline("automatic-speech-recognition", model="openai/whisper-large")
16
  transcribe_result = pipe(upload, generate_kwargs={'task': 'transcribe'})
17
  translate_result = pipe(upload, generate_kwargs={'task': 'translate'})
18
  return transcribe_result['text'], translate_result['text']
 
82
  if options == "Start a recording":
83
  audio = mic_recorder(key='my_recorder', callback=callback)
84
  elif options == "Upload an audio":
85
+ audio = st.file_uploader("Please upload an audio", type=["wav", "mp3"])
86
  else:
87
  text = st.text_area("Please input the transcript (Only support English)")
88
  button = st.button('Submit')
89
 
90
  if button:
91
+ with st.spinner(text="Loading... It may take a while if you are running the app for the first time."):
92
  model, tokenizer = load_model()
93
  if options == "Start a recording":
94
  transcibe_text, translate_text = transcribe_and_translate(upload=audio["bytes"])
95
  prediction, probability = predict(text=translate_text, model=model, tokenizer=tokenizer)
96
  elif options == "Upload an audio":
97
+ transcibe_text, translate_text = transcribe_and_translate(upload=audio.getvalue())
98
  prediction, probability = predict(text=translate_text, model=model, tokenizer=tokenizer)
99
  else:
100
  transcibe_text = text
 
112
  # Convert probability to bar
113
  st.write(f'\n')
114
  objects = ('Hardware', 'Access', 'Miscellaneous', 'HR Support', 'Purchase', 'Administrative rights', 'Storage', 'Internal Project')
115
+ df = pd.DataFrame({'Categories': objects, 'Probability': np.around(probability[0])})
116
  st.bar_chart(data=df, x='Categories', y='Probability')
117
 
118
  if __name__ == '__main__':