JLW commited on
Commit
7f1048b
·
1 Parent(s): 5ac394f

Enable Whisper

Browse files
Files changed (2) hide show
  1. app.py +23 -23
  2. requirements.txt +1 -1
app.py CHANGED
@@ -9,8 +9,8 @@ import gradio as gr
9
  import requests
10
 
11
  # UNCOMMENT TO USE WHISPER
12
- # import warnings
13
- # import whisper
14
 
15
  from langchain import ConversationChain, LLMChain
16
 
@@ -57,26 +57,26 @@ POLLY_VOICE_DATA = PollyVoiceData()
57
 
58
 
59
  # UNCOMMENT TO USE WHISPER
60
- # warnings.filterwarnings("ignore")
61
- # WHISPER_MODEL = whisper.load_model("tiny")
62
- # print("WHISPER_MODEL", WHISPER_MODEL)
63
 
64
 
65
  # UNCOMMENT TO USE WHISPER
66
- # def transcribe(aud_inp):
67
- # if aud_inp is None:
68
- # return ""
69
- # aud = whisper.load_audio(aud_inp)
70
- # aud = whisper.pad_or_trim(aud)
71
- # mel = whisper.log_mel_spectrogram(aud).to(WHISPER_MODEL.device)
72
- # _, probs = WHISPER_MODEL.detect_language(mel)
73
- # options = whisper.DecodingOptions()
74
- # result = whisper.decode(WHISPER_MODEL, mel, options)
75
- # print("result.text", result.text)
76
- # result_text = ""
77
- # if result and result.text:
78
- # result_text = result.text
79
- # return result_text
80
 
81
 
82
  # Pertains to Express-inator functionality
@@ -441,10 +441,10 @@ with gr.Blocks(css=".gradio-container {background-color: lightgray}") as block:
441
  submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
442
 
443
  # UNCOMMENT TO USE WHISPER
444
- # with gr.Row():
445
- # audio_comp = gr.Microphone(source="microphone", type="filepath", label="Just say it!",
446
- # interactive=True, streaming=False)
447
- # audio_comp.change(transcribe, inputs=[audio_comp], outputs=[message])
448
 
449
  gr.Examples(
450
  examples=["How many people live in Canada?",
 
9
  import requests
10
 
11
  # UNCOMMENT TO USE WHISPER
12
+ import warnings
13
+ import whisper
14
 
15
  from langchain import ConversationChain, LLMChain
16
 
 
57
 
58
 
59
  # UNCOMMENT TO USE WHISPER
60
+ warnings.filterwarnings("ignore")
61
+ WHISPER_MODEL = whisper.load_model("tiny")
62
+ print("WHISPER_MODEL", WHISPER_MODEL)
63
 
64
 
65
  # UNCOMMENT TO USE WHISPER
66
+ def transcribe(aud_inp):
67
+ if aud_inp is None:
68
+ return ""
69
+ aud = whisper.load_audio(aud_inp)
70
+ aud = whisper.pad_or_trim(aud)
71
+ mel = whisper.log_mel_spectrogram(aud).to(WHISPER_MODEL.device)
72
+ _, probs = WHISPER_MODEL.detect_language(mel)
73
+ options = whisper.DecodingOptions()
74
+ result = whisper.decode(WHISPER_MODEL, mel, options)
75
+ print("result.text", result.text)
76
+ result_text = ""
77
+ if result and result.text:
78
+ result_text = result.text
79
+ return result_text
80
 
81
 
82
  # Pertains to Express-inator functionality
 
441
  submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
442
 
443
  # UNCOMMENT TO USE WHISPER
444
+ with gr.Row():
445
+ audio_comp = gr.Microphone(source="microphone", type="filepath", label="Just say it!",
446
+ interactive=True, streaming=False)
447
+ audio_comp.change(transcribe, inputs=[audio_comp], outputs=[message])
448
 
449
  gr.Examples(
450
  examples=["How many people live in Canada?",
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
  openai==0.26.1
2
- gradio==3.16.1
3
  google-search-results
4
  google-api-python-client==2.72.0
5
  wolframalpha
 
1
  openai==0.26.1
2
+ gradio==3.16.2
3
  google-search-results
4
  google-api-python-client==2.72.0
5
  wolframalpha