Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import openai | |
| import random | |
| PROMPT = """首先,需要澄清的是,我方对“偏爱”的定义是:**教师基于主观喜好或对“优秀”的片面理解,给予特定学生与其学业表现或课堂行为无关的特殊待遇或关注,而忽视其他学生正当的学习需求和情感体验,从而损害教育公平的行为。**对方辩友试图将“偏爱”的对象限定为客观标准下的“优秀学生”,这是偷换概念的逻辑错误。 | |
| 即使是看似客观的评价标准,例如“成绩优秀”、“品行突出”,在实际操作中也充满了主观性。每个老师对“优秀”的理解不同,对学生行为的评价标准也不同,最终就会导致“偏爱”的对象并非真正意义上的“优秀”,而是取决于教师个人的喜好。试问,一个在数学方面有天赋但语文成绩相对较弱的学生,难道就不值得被老师关注和鼓励吗? | |
| """ | |
| def transcribe_audio(api_key, audio): | |
| if api_key is None: | |
| return "请输入openai官方apikey" | |
| if audio is None: | |
| return "没有检测到音频,可能是点击的间隔时间太短,请重新点击sumbit。如果仍然出错,请重新录音或者上传音频文件。" | |
| client = openai.OpenAI( | |
| api_key = api_key, | |
| ) | |
| try: | |
| # 使用 OpenAI Whisper API 进行转录 | |
| with open(audio, "rb") as audio_file: | |
| result = client.audio.transcriptions.create( | |
| model = "whisper-1", | |
| file = audio_file, | |
| prompt = PROMPT, | |
| ) | |
| return result.text | |
| except Exception as e: | |
| return f'转录音频时出现错误: {str(e)}' | |
| # 创建 Gradio 接口 | |
| gr.Interface( | |
| fn=transcribe_audio, | |
| inputs=[ | |
| gr.Textbox(type="password", label="API密钥", placeholder="请输入您的API密钥"), | |
| gr.Audio( | |
| sources="microphone", type="filepath", label = "录音或上传音频", interactive=True, | |
| ) | |
| ], | |
| outputs=gr.Textbox(label="转录文本", placeholder="转录的文字将显示在这里...", lines=10, interactive=True, show_copy_button=True), | |
| theme="huggingface", | |
| title="💬 Agent4DB专用语音转文字工具", | |
| description="🤟 使用 OpenAI Whisper API 将语音转录为文字", | |
| ).launch(share=True) |