Kevin676 commited on
Commit
623d74a
1 Parent(s): f6d6c77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -4
app.py CHANGED
@@ -54,6 +54,7 @@ def generate_prompt(instruction, input=None):
54
  def evaluate(
55
  # instruction,
56
  audio,
 
57
  input=None,
58
  token_count=200,
59
  temperature=1.0,
@@ -61,7 +62,7 @@ def evaluate(
61
  presencePenalty = 0.1,
62
  countPenalty = 0.1,
63
  ):
64
-
65
  # load audio and pad/trim it to fit 30 seconds
66
  audio = whisper.load_audio(audio)
67
  audio = whisper.pad_or_trim(audio)
@@ -116,13 +117,32 @@ def evaluate(
116
  out_last = i + 1
117
  gc.collect()
118
  torch.cuda.empty_cache()
119
- yield out_str.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  g = gr.Interface(
122
  fn=evaluate,
123
  inputs=[
124
  # gr.components.Textbox(lines=2, label="Instruction", value="Tell me about ravens."),
125
  gr.Audio(source="microphone", label = "请开始对话吧!", type="filepath"),
 
126
  gr.components.Textbox(lines=2, label="Input", placeholder="none"),
127
  gr.components.Slider(minimum=10, maximum=200, step=10, value=150), # token_count
128
  gr.components.Slider(minimum=0.2, maximum=2.0, step=0.1, value=1.0), # temperature
@@ -131,10 +151,15 @@ g = gr.Interface(
131
  gr.components.Slider(0.0, 1.0, step=0.1, value=0.4), # countPenalty
132
  ],
133
  outputs=[
 
 
 
 
134
  gr.inputs.Textbox(
135
  lines=5,
136
- label="Output",
137
- )
 
138
  ],
139
  title="🥳💬💕 - TalktoAI,随时随地,谈天说地!",
140
  description="🤖 - 让有人文关怀的AI造福每一个人!AI向善,文明璀璨!TalktoAI - Enable the future!",
 
54
  def evaluate(
55
  # instruction,
56
  audio,
57
+ upload,
58
  input=None,
59
  token_count=200,
60
  temperature=1.0,
 
62
  presencePenalty = 0.1,
63
  countPenalty = 0.1,
64
  ):
65
+ res = []
66
  # load audio and pad/trim it to fit 30 seconds
67
  audio = whisper.load_audio(audio)
68
  audio = whisper.pad_or_trim(audio)
 
117
  out_last = i + 1
118
  gc.collect()
119
  torch.cuda.empty_cache()
120
+
121
+ res.append(out_str.strip())
122
+
123
+ tts.tts_to_file(res, speaker_wav = upload, language="en", file_path="output.wav")
124
+
125
+ voicefixer.restore(input="output.wav", # input wav file path
126
+ output="audio1.wav", # output wav file path
127
+ cuda=True, # whether to use gpu acceleration
128
+ mode = 0) # You can try out mode 0, 1, or 2 to find out the best result
129
+
130
+ noisy = enhance_model.load_audio(
131
+ "audio1.wav"
132
+ ).unsqueeze(0)
133
+
134
+ enhanced = enhance_model.enhance_batch(noisy, lengths=torch.tensor([1.]))
135
+ torchaudio.save("enhanced.wav", enhanced.cpu(), 16000)
136
+
137
+ return [result.text, res, "enhanced.wav"]
138
+ # yield out_str.strip()
139
 
140
  g = gr.Interface(
141
  fn=evaluate,
142
  inputs=[
143
  # gr.components.Textbox(lines=2, label="Instruction", value="Tell me about ravens."),
144
  gr.Audio(source="microphone", label = "请开始对话吧!", type="filepath"),
145
+ gr.Audio(source="upload", label = "请上传您喜欢的声音(wav文件)", type="filepath"),
146
  gr.components.Textbox(lines=2, label="Input", placeholder="none"),
147
  gr.components.Slider(minimum=10, maximum=200, step=10, value=150), # token_count
148
  gr.components.Slider(minimum=0.2, maximum=2.0, step=0.1, value=1.0), # temperature
 
151
  gr.components.Slider(0.0, 1.0, step=0.1, value=0.4), # countPenalty
152
  ],
153
  outputs=[
154
+ gr.inputs.Textbox(
155
+ lines=1,
156
+ label="Speech to Text"",
157
+ ),
158
  gr.inputs.Textbox(
159
  lines=5,
160
+ label="Raven Output",
161
+ ),
162
+ gr.Audio(label="Audio with Custom Voice"),
163
  ],
164
  title="🥳💬💕 - TalktoAI,随时随地,谈天说地!",
165
  description="🤖 - 让有人文关怀的AI造福每一个人!AI向善,文明璀璨!TalktoAI - Enable the future!",