Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import torch | |
| import torchaudio | |
| from torchaudio.transforms import Resample | |
| # 定义模型路径 | |
| model_path = "https://huggingface.co/Tele-AI/TeleSpeech-ASR1.0/resolve/main/large.pt" | |
| # 下载模型文件 | |
| torch.hub.download_url_to_file(model_path, 'large.pt') | |
| # 加载模型 | |
| model = torch.jit.load('large.pt') | |
| model.eval() | |
| # 定义处理函数 | |
| def transcribe(audio): | |
| waveform, sample_rate = torchaudio.load(audio) | |
| resample = Resample(orig_freq=sample_rate, new_freq=16000) | |
| waveform = resample(waveform) | |
| input_values = waveform.unsqueeze(0) | |
| with torch.no_grad(): | |
| logits = model(input_values) | |
| predicted_ids = torch.argmax(logits, dim=-1) | |
| transcription = tokenizer.decode(predicted_ids[0]) | |
| return transcription | |
| # 创建 Gradio 界面 | |
| iface = gr.Interface( | |
| fn=transcribe, | |
| inputs=gr.Audio(source="microphone", type="filepath"), | |
| outputs="text", | |
| title="TeleSpeech ASR", | |
| description="Upload an audio file or record your voice to transcribe speech to text using the TeleSpeech ASR model." | |
| ) | |
| iface.launch() | |