Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,23 @@
|
|
1 |
-
from transformers import
|
2 |
-
from datasets import load_dataset
|
3 |
from gradio import Interface
|
4 |
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
gpt2_xl_model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2-xl")
|
9 |
|
|
|
|
|
10 |
|
11 |
def voice_chat(user_voice):
|
|
|
12 |
messages = [{"role": "system", "content": "You are a kind helpful assistant."}]
|
13 |
-
|
14 |
-
messages
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
with gpt2_xl_model.no_grad():
|
19 |
-
input_ids = gpt2_xl_model.tokenizer(messages, return_tensors="pt").input_ids
|
20 |
-
outputs = gpt2_xl_model.generate(input_ids, max_length=100)
|
21 |
-
chat_response = gpt2_xl_model.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
22 |
-
|
23 |
-
reply = chat_response
|
24 |
-
messages.append({"role": "assistant", "content": reply})
|
25 |
-
audio = tts_model.generate(text=reply, return_tensors="pt").tolist()[0][0]
|
26 |
-
return reply, audio
|
27 |
-
|
28 |
|
29 |
text_reply = Interface.Textbox(label="ChatGPT Text")
|
30 |
voice_reply = Interface.Audio(type="audio/wav")
|
|
|
1 |
+
from transformers import pipeline
|
|
|
2 |
from gradio import Interface
|
3 |
|
4 |
+
# Create a pipeline for text-to-speech
|
5 |
+
tts = pipeline("text-to-speech", model="facebook/s2s-wav2vec2-ft")
|
6 |
|
7 |
+
# Create a pipeline for speech-to-text
|
8 |
+
stt = pipeline("automatic-speech-recognition", model="openai/whisper-medium")
|
|
|
9 |
|
10 |
+
# Create a pipeline for text generation
|
11 |
+
chat = pipeline("text-generation", model="gpt-3.5-turbo")
|
12 |
|
13 |
def voice_chat(user_voice):
|
14 |
+
user_text = stt(user_voice)["text"]
|
15 |
messages = [{"role": "system", "content": "You are a kind helpful assistant."}]
|
16 |
+
messages.append({"role": "user", "content": user_text})
|
17 |
+
chat_reply = chat(messages=messages, max_length=100, top_p=0.95, temperature=0.7)[0]["generated_text"]
|
18 |
+
messages.append({"role": "assistant", "content": chat_reply})
|
19 |
+
audio = tts(chat_reply)["audio"]
|
20 |
+
return chat_reply, audio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
text_reply = Interface.Textbox(label="ChatGPT Text")
|
23 |
voice_reply = Interface.Audio(type="audio/wav")
|