Update app.py
Browse files
app.py
CHANGED
@@ -1,104 +1,14 @@
|
|
1 |
-
import
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
-
import gradio as gr
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
)
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
for user_prompt, bot_response in history:
|
15 |
-
prompt += f"[INST] {user_prompt} [/INST]"
|
16 |
-
prompt += f" {bot_response}</s> "
|
17 |
-
prompt += f"[INST] {message} [/INST]"
|
18 |
-
return prompt
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
)
|
23 |
-
temperature = float(temperature)
|
24 |
-
if temperature < 1e-2:
|
25 |
-
temperature = 1e-2
|
26 |
-
top_p = float(top_p)
|
27 |
-
|
28 |
-
generate_kwargs = dict(
|
29 |
-
temperature=temperature,
|
30 |
-
max_new_tokens=max_new_tokens,
|
31 |
-
top_p=top_p,
|
32 |
-
repetition_penalty=repetition_penalty,
|
33 |
-
do_sample=True,
|
34 |
-
seed=42,
|
35 |
-
)
|
36 |
-
|
37 |
-
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
38 |
-
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
39 |
-
output = ""
|
40 |
-
|
41 |
-
for response in stream:
|
42 |
-
output += response.token.text
|
43 |
-
yield output
|
44 |
-
|
45 |
-
# Озвучивание ответа
|
46 |
-
engine.say(output)
|
47 |
-
engine.runAndWait()
|
48 |
-
|
49 |
-
return output
|
50 |
-
|
51 |
-
additional_inputs = [
|
52 |
-
gr.Textbox(
|
53 |
-
label="System Prompt",
|
54 |
-
max_lines=1,
|
55 |
-
interactive=True,
|
56 |
-
),
|
57 |
-
gr.Slider(
|
58 |
-
label="Temperature",
|
59 |
-
value=0.1,
|
60 |
-
minimum=0.0,
|
61 |
-
maximum=1.0,
|
62 |
-
step=0.05,
|
63 |
-
interactive=True,
|
64 |
-
info="Higher values produce more diverse outputs",
|
65 |
-
),
|
66 |
-
gr.Slider(
|
67 |
-
label="Max new tokens",
|
68 |
-
value=1024,
|
69 |
-
minimum=128,
|
70 |
-
maximum=8192,
|
71 |
-
step=64,
|
72 |
-
interactive=True,
|
73 |
-
info="The maximum numbers of new tokens",
|
74 |
-
),
|
75 |
-
gr.Slider(
|
76 |
-
label="Top-p (nucleus sampling)",
|
77 |
-
value=0.90,
|
78 |
-
minimum=0.0,
|
79 |
-
maximum=1,
|
80 |
-
step=0.05,
|
81 |
-
interactive=True,
|
82 |
-
info="Higher values sample more low-probability tokens",
|
83 |
-
),
|
84 |
-
gr.Slider(
|
85 |
-
label="Repetition penalty",
|
86 |
-
value=1.2,
|
87 |
-
minimum=1.0,
|
88 |
-
maximum=2.0,
|
89 |
-
step=0.05,
|
90 |
-
interactive=True,
|
91 |
-
info="Penalize repeated tokens",
|
92 |
-
)
|
93 |
-
]
|
94 |
-
|
95 |
-
examples = []
|
96 |
-
|
97 |
-
gr.ChatInterface(
|
98 |
-
fn=generate,
|
99 |
-
chatbot=gr.Chatbot(show_label=False, show_share_button=True, show_copy_button=True, likeable=True, layout="panel"),
|
100 |
-
additional_inputs=additional_inputs,
|
101 |
-
title="theGame",
|
102 |
-
examples=examples,
|
103 |
-
concurrency_limit=20,
|
104 |
-
).launch(show_api=False)
|
|
|
1 |
+
from transformers import pipeline
|
|
|
|
|
2 |
|
3 |
+
# Инициализация пайплайна для синтеза речи
|
4 |
+
tts = pipeline("text-to-speech", model="facebook/tts_transformer-es-ljspeech")
|
|
|
5 |
|
6 |
+
# Пример текста
|
7 |
+
text = "Привет, как ты?"
|
8 |
|
9 |
+
# Генерация аудиофайла
|
10 |
+
audio = tts(text)
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Сохранение аудиофайла
|
13 |
+
with open("output_audio.wav", "wb") as f:
|
14 |
+
f.write(audio["audio"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|