import gradio as gr import pandas as pd import plotly.express as px def plot_csv(df): # 将第一列作为索引 df.set_index('Model', inplace=True) # 转置数据框,使得模型作为列,横轴作为行 df_transposed = df.T # 使用plotly绘制折线图 fig = px.line(df_transposed, x=df_transposed.index, y=df_transposed.columns, title='Model Evaluation Results', labels={'value': 'Evaluation Score', 'index': 'Evaluation Metric'}, color_discrete_sequence=px.colors.qualitative.Plotly) # 设置悬停效果 fig.update_traces(hovertemplate='%{y}') return fig # 读取本地的CSV文件 file_path = 'line_counts_QS.csv' df = pd.read_csv(file_path) iface = gr.Interface( fn=plot_csv, inputs=gr.Dataframe(df), outputs=gr.Plot(label="Line Plot"), title="CSV to Line Plot", description="Visualize the evaluation results as a line plot." ) iface.launch()