Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py (放到 Hugging Face Space)
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
# 加载模型(HF Hub 会自动从 hub 下载)
|
| 6 |
+
asr = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
| 7 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 8 |
+
|
| 9 |
+
def process(audio_path):
|
| 10 |
+
# 1) 语音转写
|
| 11 |
+
res = asr(audio_path)
|
| 12 |
+
text = res.get("text", "").strip()
|
| 13 |
+
if not text:
|
| 14 |
+
return "转写失败,请上传清晰录音。"
|
| 15 |
+
# 2) 生成摘要(短总结)
|
| 16 |
+
# 对长文本可以分段后合并
|
| 17 |
+
summary = summarizer(text, max_length=120, min_length=30, do_sample=False)[0]["summary_text"]
|
| 18 |
+
# 3) 简单结构化示例(问题/回答抽取可以后续加)
|
| 19 |
+
output = f"=== 转写 ===\n{text}\n\n=== 摘要 ===\n{summary}"
|
| 20 |
+
return output
|
| 21 |
+
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=process,
|
| 24 |
+
inputs=gr.Audio(source=["upload","microphone"], type="filepath"),
|
| 25 |
+
outputs="text",
|
| 26 |
+
title="AI 面试记录助手(MVP)",
|
| 27 |
+
description="上传面试录音,自动转写并生成面试摘要。使用后请填写反馈表(链接)"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
demo.launch()
|