DamonDemon's picture
refine data
6f5b41f
raw
history blame
1.49 kB
import gradio as gr
import pandas as pd
# Load the uc_result.csv file
uc_result_df = pd.read_csv('uc_result.csv')
# Convert percentage columns to float for sorting
percentage_columns = [col for col in uc_result_df.columns if uc_result_df[col].dtype == 'object' and '%' in uc_result_df[col].iloc[0]]
for col in percentage_columns:
uc_result_df[col] = uc_result_df[col].str.rstrip('%').astype('float') / 100
# Define a function to filter and sort the dataframe
def filter_and_sort(method=None, sort_by=None, ascending=True):
filtered_df = uc_result_df
if method:
filtered_df = filtered_df[filtered_df['Method'].str.contains(method)]
if sort_by:
filtered_df = filtered_df.sort_values(by=sort_by, ascending=ascending)
return filtered_df
# Create Gradio interface components
method_input = gr.inputs.Textbox(label="Filter by Method", placeholder="Enter method name...")
sort_by_dropdown = gr.inputs.Dropdown(label="Sort by", choices=uc_result_df.columns.tolist(), default=None)
ascending_checkbox = gr.inputs.Checkbox(label="Ascending Order", value=True)
# Create a Gradio interface to display the data
iface = gr.Interface(
fn=filter_and_sort,
inputs=[method_input, sort_by_dropdown, ascending_checkbox],
outputs=gr.outputs.DataFrame(type="pandas"),
title="Enhanced UC Results Display",
description="This interface allows filtering and sorting of the results from uc_result.csv"
)
if __name__ == "__main__":
iface.launch()