import gradio as gr import pandas as pd def process_excel(file): df = pd.read_excel(file.name, engine='openpyxl') return df,type(df) iface = gr.Interface(fn=process_excel, inputs=gr.File(type='file',label='excle'), outputs=[gr.outputs.Dataframe(type='pandas'),"text"], title="Excel Processor") iface.launch() # def merge_excel_tables(file_path1, file_path2): # df1 = process_excel(file_path1) # df2 = process_excel(file_path2) # merged_df = df1.merge(df2, left_on=list(df1.columns)[0], right_on=list(df2.columns)[0], how='left') # column_mapping = {} # for col in df1.columns: # column_mapping[col] = col # for col in merged_df.columns: # if col.endswith('_x'): # new_col = col[:-2] # 去除_x后缀 # if new_col in column_mapping: # column_mapping[new_col] = new_col # 如果存在相同的列名,保持不变 # merged_df.rename(columns={col: new_col}, inplace=True) # elif col.endswith('_y'): # new_col = col[:-2] # 去除_y后缀 # merged_df.rename(columns={col: new_col}, inplace=True) # merged_df = merged_df.dropna(axis=1, how='all') # merged_df = merged_df[list(df1.columns)] # # merged_df.to_excel(output_file, index=False) # return merged_df # iface = gr.Interface(fn=merge_excel_tables, inputs=["file", "file"], outputs=gr.outputs.Dataframe(type='pandas'), title="Excel Processor", description="根据表格一的第一列,寻找表格二对应第一列的行数据,把表格二中与表格一相同标签数据填入表格一") # iface.launch()