import gradio as gr import os model = gr.load("models/fnlp/bart-base-chinese") def generate_summary(file): # 读取上传的文本文件内容 with open(file.name, 'r', encoding='utf-8') as f: text_content = f.read() print("File Content:", text_content) # 添加此行进行调试 # 使用模型进行处理(在这里是摘要生成,你可以替换为你的具体模型处理逻辑) result = model.predict(text_content) return result def read_file_content(file): # 读取上传的文本文件内容 with open(file.name, 'r', encoding='utf-8') as f: text_content = f.read() return text_content demo = gr.Interface( fn=generate_summary, inputs=gr.File(), outputs="text", live=False ) # 增加一个上传文件后读取文件内容的接口 file_reader = gr.Interface( fn=read_file_content, inputs=gr.File(), outputs="text", live=False ) # 启动应用 demo.launch(share=True)