import gradio as gr import my_uie import face_emo_analysize def text_emo_analysize(text): text_outcome = my_uie.emo_analy(text) return text_outcome def face_emo_analyze(): # 假设 face_emo_analysize.face_emo_analysize() 会打开摄像头并捕获表情 face_outcome = face_emo_analysize.face_emo_analysize() return face_outcome # 创建Gradio界面 with gr.Blocks() as demo: gr.Markdown("# 情感分析应用") gr.Markdown("输入信息,获取情感分析结果。") with gr.Row(): with gr.Column(): text_input = gr.Textbox(lines=2, placeholder='在这里输入文本') text_submit_button = gr.Button("提交文本情感分析") text_output = gr.Textbox(label="文本情感分析结果") with gr.Row(): face_button = gr.Button("执行面部情感分析") face_output = gr.Textbox(label="面部情感分析结果") def on_face_button_click(): # 调用 face_emo_analyze 函数并返回结果 face_outcome = face_emo_analyze() return face_outcome face_button.click(on_face_button_click, inputs=None, outputs=face_output) text_submit_button.click(text_emo_analysize, inputs=text_input, outputs=text_output) demo.launch()