Run on CPU
Browse files8 unmodified lines91011121314151660 unmodified lines7778798081828384858687888990919293949596979899100101102103104105495 unmodified lines6016026036046056066076086096108 unmodified linesimport requests# UNCOMMENT TO USE WHISPERimport warningsimport whisperfrom langchain import ConversationChain, LLMChain60 unmodified lines# UNCOMMENT TO USE WHISPERwarnings.filterwarnings("ignore")WHISPER_MODEL = whisper.load_model("tiny")print("WHISPER_MODEL", WHISPER_MODEL)# UNCOMMENT TO USE WHISPERdef transcribe(aud_inp, whisper_lang):if aud_inp is None:return ""aud = whisper.load_audio(aud_inp)aud = whisper.pad_or_trim(aud)mel = whisper.log_mel_spectrogram(aud).to(WHISPER_MODEL.device)_, probs = WHISPER_MODEL.detect_language(mel)options = whisper.DecodingOptions()if whisper_lang != WHISPER_DETECT_LANG:whisper_lang_code = POLLY_VOICE_DATA.get_whisper_lang_code(whisper_lang)options = whisper.DecodingOptions(language=whisper_lang_code)result = whisper.decode(WHISPER_MODEL, mel, options)print("result.text", result.text)result_text = ""if result and result.text:result_text = result.textreturn result_text# Pertains to Express-inator functionality495 unmodified linessubmit = gr.Button(value="Send", variant="secondary").style(full_width=False)# UNCOMMENT TO USE WHISPERwith gr.Row():audio_comp = gr.Microphone(source="microphone", type="filepath", label="Just say it!",interactive=True, streaming=False)audio_comp.change(transcribe, inputs=[audio_comp, whisper_lang_state], outputs=[message])gr.Examples(examples=["How many people live in Canada?",8 unmodified lines91011121314151660 unmodified lines7778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123495 unmodified lines6196206216226236246256266276286296306316326338 unmodified linesimport requests# UNCOMMENT TO USE WHISPER# import warnings# import whisperfrom langchain import ConversationChain, LLMChain60 unmodified lines# UNCOMMENT TO USE WHISPER# warnings.filterwarnings("ignore")# WHISPER_MODEL = whisper.load_model("tiny")# print("WHISPER_MODEL", WHISPER_MODEL)# UNCOMMENT TO USE WHISPER# def transcribe(aud_inp, whisper_lang):# if aud_inp is None:# return ""# aud = whisper.load_audio(aud_inp)# aud = whisper.pad_or_trim(aud)# mel = whisper.log_mel_spectrogram(aud).to(WHISPER_MODEL.device)# _, probs = WHISPER_MODEL.detect_language(mel)# options = whisper.DecodingOptions()# if whisper_lang != WHISPER_DETECT_LANG:# whisper_lang_code = POLLY_VOICE_DATA.get_whisper_lang_code(whisper_lang)# options = whisper.DecodingOptions(language=whisper_lang_code)# result = whisper.decode(WHISPER_MODEL, mel, options)# print("result.text", result.text)# result_text = ""# if result and result.text:# result_text = result.text# return result_text# TEMPORARY FOR TESTINGdef transcribe_dummy(aud_inp_tb, whisper_lang):if aud_inp_tb is None:return ""# aud = whisper.load_audio(aud_inp)# aud = whisper.pad_or_trim(aud)# mel = whisper.log_mel_spectrogram(aud).to(WHISPER_MODEL.device)# _, probs = WHISPER_MODEL.detect_language(mel)# options = whisper.DecodingOptions()# options = whisper.DecodingOptions(language="ja")# result = whisper.decode(WHISPER_MODEL, mel, options)result_text = "Whisper will detect language"if whisper_lang != WHISPER_DETECT_LANG:whisper_lang_code = POLLY_VOICE_DATA.get_whisper_lang_code(whisper_lang)result_text = f"Whisper will use lang code: {whisper_lang_code}"print("result_text", result_text)return aud_inp_tb# Pertains to Express-inator functionality495 unmodified linessubmit = gr.Button(value="Send", variant="secondary").style(full_width=False)# UNCOMMENT TO USE WHISPER# with gr.Row():# audio_comp = gr.Microphone(source="microphone", type="filepath", label="Just say it!",# interactive=True, streaming=False)# audio_comp.change(transcribe, inputs=[audio_comp, whisper_lang_state], outputs=[message])# TEMPORARY FOR TESTING# with gr.Row():# audio_comp_tb = gr.Textbox(label="Just say it!", lines=1)# audio_comp_tb.submit(transcribe_dummy, inputs=[audio_comp_tb, whisper_lang_state], outputs=[message])gr.Examples(examples=["How many people live in Canada?",
app.py+46-23