Spaces:
Build error
Build error
Commit
·
84a239d
1
Parent(s):
40d6b94
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,18 +12,19 @@ import json
|
|
| 12 |
import soundfile as sf
|
| 13 |
|
| 14 |
|
|
|
|
|
|
|
| 15 |
device = 0 if torch.cuda.is_available() else "cpu"
|
| 16 |
|
|
|
|
| 17 |
pipe = pipeline(
|
| 18 |
task="automatic-speech-recognition",
|
| 19 |
-
model="openai/whisper-
|
| 20 |
chunk_length_s=30,
|
| 21 |
device=device,
|
| 22 |
-
)
|
| 23 |
-
|
| 24 |
-
session_token = os.environ.get("SessionToken")
|
| 25 |
|
| 26 |
-
#
|
| 27 |
tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmpdir_tts", overrides={"max_decoder_steps": 2000}, run_opts={"device":device})
|
| 28 |
hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmpdir_vocoder")
|
| 29 |
|
|
@@ -46,7 +47,7 @@ def chat(input_audio, chat_history, reset_conversation):
|
|
| 46 |
# text -> response (chatGPT)
|
| 47 |
response = get_response_from_chatbot(message, reset_conversation)
|
| 48 |
|
| 49 |
-
# response -> speech (
|
| 50 |
mel_output, mel_length, alignment = tacotron2.encode_text(response)
|
| 51 |
wav = hifi_gan.decode_batch(mel_output)
|
| 52 |
sf.write("out.wav", wav.squeeze().cpu().numpy(), 22050)
|
|
@@ -150,6 +151,7 @@ start_work= """async() => {
|
|
| 150 |
|
| 151 |
with gr.Blocks(title="Talk to chatGPT") as demo:
|
| 152 |
gr.Markdown("## Talk to chatGPT ##")
|
|
|
|
| 153 |
gr.HTML("<p>You can duplicate this space and use your own session token: <a style='display:inline-block' href='https://huggingface.co/spaces/yizhangliu/chatGPT?duplicate=true'><img src='https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=10' alt='Duplicate Space'></a></p>")
|
| 154 |
gr.HTML("<p> Instruction on how to get session token can be seen in video <a style='display:inline-block' href='https://www.youtube.com/watch?v=TdNSj_qgdFk'><font style='color:blue;weight:bold;'>here</font></a>. Add your session token by going to settings and add under secrets. </p>")
|
| 155 |
with gr.Group(elem_id="page_1", visible=True) as page_1:
|
|
|
|
| 12 |
import soundfile as sf
|
| 13 |
|
| 14 |
|
| 15 |
+
session_token = os.environ.get("SessionToken")
|
| 16 |
+
|
| 17 |
device = 0 if torch.cuda.is_available() else "cpu"
|
| 18 |
|
| 19 |
+
# Intialise STT (Whisper)
|
| 20 |
pipe = pipeline(
|
| 21 |
task="automatic-speech-recognition",
|
| 22 |
+
model="openai/whisper-base.en",
|
| 23 |
chunk_length_s=30,
|
| 24 |
device=device,
|
| 25 |
+
)
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
# Intialise TTS (tacotron2) and Vocoder (HiFIGAN)
|
| 28 |
tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmpdir_tts", overrides={"max_decoder_steps": 2000}, run_opts={"device":device})
|
| 29 |
hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmpdir_vocoder")
|
| 30 |
|
|
|
|
| 47 |
# text -> response (chatGPT)
|
| 48 |
response = get_response_from_chatbot(message, reset_conversation)
|
| 49 |
|
| 50 |
+
# response -> speech (tacotron2)
|
| 51 |
mel_output, mel_length, alignment = tacotron2.encode_text(response)
|
| 52 |
wav = hifi_gan.decode_batch(mel_output)
|
| 53 |
sf.write("out.wav", wav.squeeze().cpu().numpy(), 22050)
|
|
|
|
| 151 |
|
| 152 |
with gr.Blocks(title="Talk to chatGPT") as demo:
|
| 153 |
gr.Markdown("## Talk to chatGPT ##")
|
| 154 |
+
gr.HTML("<p> Demo uses <a href='https://huggingface.co/openai/whisper-base.en'>Whisper</a> to convert the input speech to transcribed text, <a href='https://chat.openai.com/chat'>chatGPT</a> to generate responses, and <a href='https://huggingface.co/speechbrain/tts-tacotron2-ljspeech'>tacotron2</a> to convert the response to output speech. </p>")
|
| 155 |
gr.HTML("<p>You can duplicate this space and use your own session token: <a style='display:inline-block' href='https://huggingface.co/spaces/yizhangliu/chatGPT?duplicate=true'><img src='https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=10' alt='Duplicate Space'></a></p>")
|
| 156 |
gr.HTML("<p> Instruction on how to get session token can be seen in video <a style='display:inline-block' href='https://www.youtube.com/watch?v=TdNSj_qgdFk'><font style='color:blue;weight:bold;'>here</font></a>. Add your session token by going to settings and add under secrets. </p>")
|
| 157 |
with gr.Group(elem_id="page_1", visible=True) as page_1:
|