Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,19 +10,24 @@ model = WhisperForConditionalGeneration.from_pretrained(model_name)
|
|
| 10 |
|
| 11 |
# 加载数据集 bigcode/the-stack
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
-
def transcribe(
|
| 16 |
-
#
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
with torch.no_grad():
|
| 19 |
-
logits = model(
|
|
|
|
| 20 |
predicted_ids = torch.argmax(logits, dim=-1)
|
| 21 |
transcription = processor.batch_decode(predicted_ids)
|
| 22 |
|
| 23 |
# 返回转录结果
|
| 24 |
return transcription[0]
|
| 25 |
|
|
|
|
| 26 |
# Gradio 界面
|
| 27 |
iface = gr.Interface(
|
| 28 |
fn=transcribe,
|
|
|
|
| 10 |
|
| 11 |
# 加载数据集 bigcode/the-stack
|
| 12 |
|
| 13 |
+
ds = load_dataset("CoIR-Retrieval/CodeSearchNet-php-queries-corpus")
|
| 14 |
|
| 15 |
+
def transcribe(audio_path):
|
| 16 |
+
# 加载音频文件并转换为信号
|
| 17 |
+
audio, sr = librosa.load(audio_path, sr=16000)
|
| 18 |
+
input_values = processor(audio, return_tensors="pt", sampling_rate=16000).input_values
|
| 19 |
+
|
| 20 |
+
# 模型推理
|
| 21 |
with torch.no_grad():
|
| 22 |
+
logits = model(input_values).logits
|
| 23 |
+
|
| 24 |
predicted_ids = torch.argmax(logits, dim=-1)
|
| 25 |
transcription = processor.batch_decode(predicted_ids)
|
| 26 |
|
| 27 |
# 返回转录结果
|
| 28 |
return transcription[0]
|
| 29 |
|
| 30 |
+
|
| 31 |
# Gradio 界面
|
| 32 |
iface = gr.Interface(
|
| 33 |
fn=transcribe,
|