import gradio as gr from transformers import pipeline # ✅ 使用Whisper大型模型(准确率最高) asr = pipeline("automatic-speech-recognition", model="openai/whisper-large-v2") # ✅ 使用中文T5摘要模型 summarizer = pipeline( "text2text-generation", model="IDEA-CCNL/Randeng-T5-1.3B-Summary-Chinese", ) def process(audio_path, progress=gr.Progress()): try: progress(0, desc="🎧 正在识别中文语音...") result = asr(audio_path) text = result.get("text", "").strip() except Exception as e: return f"❌ 转写失败:{str(e)}" if not text: return "⚠️ 没有识别出文字,请确认音频清晰且为中文内容。" progress(0.6, desc="🧠 正在生成中文摘要...") try: summary = summarizer(f"请总结以下中文内容:{text}", max_length=100, do_sample=False)[0]["generated_text"] except Exception: summary = "⚠️ 摘要生成失败,请稍后重试。" progress(1.0, desc="✅ 完成!") return f"🎧【转写结果】\n{text}\n\n🧠【摘要】\n{summary}" demo = gr.Interface( fn=process, inputs=gr.Audio(type="filepath", label="上传中文面试录音(支持 mp3 / wav)"), outputs="text", title="🎙️ AI 中文面试复盘助手", description="上传面试录音,自动中文转写 + 中文摘要。", ) if __name__ == "__main__": demo.launch()