Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -38,26 +38,21 @@ run_opts={"device":"cuda"},
|
|
38 |
def generate_prompt(instruction, input=None):
|
39 |
if input:
|
40 |
return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
41 |
-
|
42 |
# Instruction:
|
43 |
{instruction}
|
44 |
-
|
45 |
# Input:
|
46 |
{input}
|
47 |
-
|
48 |
# Response:
|
49 |
"""
|
50 |
else:
|
51 |
return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
52 |
-
|
53 |
# Instruction:
|
54 |
{instruction}
|
55 |
-
|
56 |
# Response:
|
57 |
"""
|
58 |
|
59 |
def evaluate(
|
60 |
-
|
61 |
audio,
|
62 |
# instruction,
|
63 |
# input=None,
|
@@ -90,8 +85,7 @@ def evaluate(
|
|
90 |
token_ban = [], # ban the generation of some tokens
|
91 |
token_stop = [0]) # stop generation whenever you see any token here
|
92 |
|
93 |
-
|
94 |
-
instruction = result.text
|
95 |
input=None
|
96 |
# input = input.strip()
|
97 |
ctx = generate_prompt(instruction, input)
|
@@ -128,16 +122,30 @@ def evaluate(
|
|
128 |
|
129 |
res.append(out_str.strip())
|
130 |
|
131 |
-
res1 = '
|
132 |
|
133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
# yield out_str.strip()
|
136 |
|
137 |
g = gr.Interface(
|
138 |
fn=evaluate,
|
139 |
inputs=[
|
140 |
-
|
141 |
gr.Audio(source="microphone", label = "和您的专属AI聊天吧!", type="filepath"),
|
142 |
# gr.components.Textbox(lines=2, label="Instruction", value="Tell me about ravens."),
|
143 |
# gr.components.Textbox(lines=2, label="Input", placeholder="none"),
|
@@ -148,13 +156,13 @@ g = gr.Interface(
|
|
148 |
# gr.components.Slider(0.0, 1.0, step=0.1, value=0.4), # countPenalty
|
149 |
],
|
150 |
outputs=[
|
151 |
-
|
152 |
gr.Textbox(label="Raven Output"),
|
153 |
-
|
154 |
],
|
155 |
title="🥳💬💕 - TalktoAI,随时随地,谈天说地!",
|
156 |
description="🤖 - 让有人文关怀的AI造福每一个人!AI向善,文明璀璨!TalktoAI - Enable the future!",
|
157 |
article = "Powered by the RWKV Language Model"
|
158 |
)
|
159 |
g.queue(concurrency_count=1, max_size=10)
|
160 |
-
g.launch(show_error=True)
|
|
|
38 |
def generate_prompt(instruction, input=None):
|
39 |
if input:
|
40 |
return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
|
|
41 |
# Instruction:
|
42 |
{instruction}
|
|
|
43 |
# Input:
|
44 |
{input}
|
|
|
45 |
# Response:
|
46 |
"""
|
47 |
else:
|
48 |
return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
|
|
49 |
# Instruction:
|
50 |
{instruction}
|
|
|
51 |
# Response:
|
52 |
"""
|
53 |
|
54 |
def evaluate(
|
55 |
+
upload,
|
56 |
audio,
|
57 |
# instruction,
|
58 |
# input=None,
|
|
|
85 |
token_ban = [], # ban the generation of some tokens
|
86 |
token_stop = [0]) # stop generation whenever you see any token here
|
87 |
|
88 |
+
instruction = result.text.strip()
|
|
|
89 |
input=None
|
90 |
# input = input.strip()
|
91 |
ctx = generate_prompt(instruction, input)
|
|
|
122 |
|
123 |
res.append(out_str.strip())
|
124 |
|
125 |
+
res1 = ''.join(str(x) for x in res)
|
126 |
|
127 |
+
tts.tts_to_file(res1, speaker_wav = upload, language="en", file_path="output.wav")
|
128 |
+
|
129 |
+
voicefixer.restore(input="output.wav", # input wav file path
|
130 |
+
output="audio1.wav", # output wav file path
|
131 |
+
cuda=True, # whether to use gpu acceleration
|
132 |
+
mode = 0) # You can try out mode 0, 1, or 2 to find out the best result
|
133 |
+
|
134 |
+
noisy = enhance_model.load_audio(
|
135 |
+
"audio1.wav"
|
136 |
+
).unsqueeze(0)
|
137 |
+
|
138 |
+
enhanced = enhance_model.enhance_batch(noisy, lengths=torch.tensor([1.]))
|
139 |
+
torchaudio.save("enhanced.wav", enhanced.cpu(), 16000)
|
140 |
+
|
141 |
+
return [result.text, res, "enhanced.wav"]
|
142 |
|
143 |
# yield out_str.strip()
|
144 |
|
145 |
g = gr.Interface(
|
146 |
fn=evaluate,
|
147 |
inputs=[
|
148 |
+
gr.Audio(source="upload", label = "请上传您喜欢的声音(wav文件)", type="filepath"),
|
149 |
gr.Audio(source="microphone", label = "和您的专属AI聊天吧!", type="filepath"),
|
150 |
# gr.components.Textbox(lines=2, label="Instruction", value="Tell me about ravens."),
|
151 |
# gr.components.Textbox(lines=2, label="Input", placeholder="none"),
|
|
|
156 |
# gr.components.Slider(0.0, 1.0, step=0.1, value=0.4), # countPenalty
|
157 |
],
|
158 |
outputs=[
|
159 |
+
gr.Textbox(label="Speech to Text"),
|
160 |
gr.Textbox(label="Raven Output"),
|
161 |
+
gr.Audio(label="Audio with Custom Voice"),
|
162 |
],
|
163 |
title="🥳💬💕 - TalktoAI,随时随地,谈天说地!",
|
164 |
description="🤖 - 让有人文关怀的AI造福每一个人!AI向善,文明璀璨!TalktoAI - Enable the future!",
|
165 |
article = "Powered by the RWKV Language Model"
|
166 |
)
|
167 |
g.queue(concurrency_count=1, max_size=10)
|
168 |
+
g.launch(show_error=True)
|