Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -17,43 +17,15 @@ canary_model.change_decoding_strategy(decode_cfg)
|
|
17 |
|
18 |
|
19 |
|
20 |
-
|
21 |
-
# Load the text processing model and tokenizer
|
22 |
-
proc_tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
|
23 |
-
proc_model = AutoModelForCausalLM.from_pretrained(
|
24 |
-
"microsoft/Phi-3-mini-4k-instruct",
|
25 |
-
trust_remote_code=True,
|
26 |
-
)
|
27 |
-
proc_model.eval()
|
28 |
-
proc_model.to('cpu')
|
29 |
-
|
30 |
-
|
31 |
-
# Load the TTS model
|
32 |
-
tts_model = VitsModel.from_pretrained("facebook/mms-tts-eng")
|
33 |
-
tts_tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-eng")
|
34 |
-
tts_model.eval()
|
35 |
-
tts_model.to('cpu')
|
36 |
-
|
37 |
-
|
38 |
-
def process_speech(speech):
|
39 |
# Convert the speech to text
|
40 |
transcription = canary_model.transcribe(
|
41 |
speech,
|
42 |
logprobs=False,
|
43 |
)
|
44 |
|
45 |
-
|
46 |
-
inputs = proc_tokenizer.encode(transcription + proc_tokenizer.eos_token, return_tensors='pt')
|
47 |
-
outputs = proc_model.generate(inputs, max_length=100, temperature=0.7, pad_token_id=proc_tokenizer.eos_token_id)
|
48 |
-
text = proc_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
49 |
-
processed_text = tts_tokenizer(text, return_tensors="pt")
|
50 |
-
|
51 |
-
# Convert the processed text to speech
|
52 |
-
with torch.no_grad():
|
53 |
-
audio = tts_model(**inputs).waveform
|
54 |
-
|
55 |
-
return audio
|
56 |
|
57 |
-
iface = gr.Interface(fn=
|
58 |
|
59 |
iface.launch()
|
|
|
17 |
|
18 |
|
19 |
|
20 |
+
def convert_speech(speech):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
# Convert the speech to text
|
22 |
transcription = canary_model.transcribe(
|
23 |
speech,
|
24 |
logprobs=False,
|
25 |
)
|
26 |
|
27 |
+
return transcription
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
iface = gr.Interface(fn=convert_speech, inputs=gr.inputs.Audio(source="microphone"), outputs="text")
|
30 |
|
31 |
iface.launch()
|