import gradio as gr import pandas as pd def process_file(file, question): # 读取文件 if file.name.endswith('.csv'): df = pd.read_csv(file) else: df = pd.read_excel(file) # 将 DataFrame 转换为字符串 df_string = df.to_string() # 返回 DataFrame 字符串和用户问题 return df_string + "\nQ: " + question iface = gr.Interface( fn=process_file, inputs=[gr.File(label="Upload your file"), gr.Textbox(label="Your Question")], outputs=gr.Text(label="Output") ) iface.launch()