Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
"""
|
7 |
-
client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
|
8 |
|
|
|
|
|
9 |
|
10 |
def respond(
|
11 |
message,
|
@@ -15,6 +18,7 @@ def respond(
|
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
|
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
for val in history:
|
@@ -26,7 +30,6 @@ def respond(
|
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
response = ""
|
29 |
-
|
30 |
for message in client.chat_completion(
|
31 |
messages,
|
32 |
max_tokens=max_tokens,
|
@@ -35,30 +38,34 @@ def respond(
|
|
35 |
top_p=top_p,
|
36 |
):
|
37 |
token = message.choices[0].delta.content
|
38 |
-
|
39 |
response += token
|
40 |
yield response
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
46 |
demo = gr.ChatInterface(
|
47 |
respond,
|
48 |
additional_inputs=[
|
49 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
50 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
-
gr.Slider(
|
53 |
-
minimum=0.1,
|
54 |
-
maximum=1.0,
|
55 |
-
value=0.95,
|
56 |
-
step=0.05,
|
57 |
-
label="Top-p (nucleus sampling)",
|
58 |
-
),
|
59 |
],
|
60 |
)
|
61 |
|
62 |
-
|
63 |
if __name__ == "__main__":
|
64 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
import soundfile as sf
|
4 |
+
import torch
|
5 |
+
from transformers import pipeline
|
6 |
|
7 |
+
# Set up your TTS model (as before)
|
8 |
+
synthesiser = pipeline("text-to-speech", "Futuresony/output")
|
|
|
|
|
9 |
|
10 |
+
# Set up your text generation client
|
11 |
+
client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
|
12 |
|
13 |
def respond(
|
14 |
message,
|
|
|
18 |
temperature,
|
19 |
top_p,
|
20 |
):
|
21 |
+
# Generate text response from your model
|
22 |
messages = [{"role": "system", "content": system_message}]
|
23 |
|
24 |
for val in history:
|
|
|
30 |
messages.append({"role": "user", "content": message})
|
31 |
|
32 |
response = ""
|
|
|
33 |
for message in client.chat_completion(
|
34 |
messages,
|
35 |
max_tokens=max_tokens,
|
|
|
38 |
top_p=top_p,
|
39 |
):
|
40 |
token = message.choices[0].delta.content
|
|
|
41 |
response += token
|
42 |
yield response
|
43 |
|
44 |
+
# Convert the generated text into speech (Text-to-Speech)
|
45 |
+
# Get speaker embedding (optional, if you want to control the speaker)
|
46 |
+
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
47 |
+
speaker_embedding = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
48 |
+
|
49 |
+
# Generate speech from the text response
|
50 |
+
speech = synthesiser(response, forward_params={"speaker_embeddings": speaker_embedding})
|
51 |
|
52 |
+
# Save the speech to a file (you can play it on the fly or return it in other formats like MP3)
|
53 |
+
sf.write("generated_speech.wav", speech["audio"], samplerate=speech["sampling_rate"])
|
54 |
+
|
55 |
+
return response, "generated_speech.wav"
|
56 |
+
# You can return the text along with speech if needed
|
57 |
+
|
58 |
+
|
59 |
+
# Create the Gradio interface
|
60 |
demo = gr.ChatInterface(
|
61 |
respond,
|
62 |
additional_inputs=[
|
63 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
64 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
65 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
66 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
],
|
68 |
)
|
69 |
|
|
|
70 |
if __name__ == "__main__":
|
71 |
demo.launch()
|