Spaces:
Running
Running
import gradio as gr | |
import pandas as pd | |
def display_csv(file, supplier): | |
df = pd.read_csv(file.name) | |
# Define supplier-specific filters | |
vendor_filters = { | |
"Supplier 1": lambda df: df[~df['Vendor'].isin(["Seed", "EverColor", "Candy Magic", "OLENS", "Fairy", "Shobido", "Geo Medical", "Ann365"])], | |
"Supplier 2": lambda df: df[df['Vendor'].isin(["Candy Magic", "OLENS", "Fairy", "Shobido"])], | |
"Supplier 3": lambda df: df[df['Vendor'].isin(["Seed", "EverColor"])], | |
"Supplier 4": lambda df: df[df['Vendor'] == "Geo Medical"], | |
"Supplier 5": lambda df: df[df['Vendor'] == "Ann365"] | |
} | |
# Apply filter based on selected supplier | |
if supplier and supplier in vendor_filters: | |
df = vendor_filters[supplier](df) | |
# Specify columns for output | |
columns_to_include = [ | |
'Order Number', 'Quantity', 'Product Title', 'Product Option Name', | |
'Product Option Value', 'Order Line item Properties 2 Name', | |
'Order Line item Properties 2 Value', 'Order Line item Properties 3 Name', | |
'Order Line item Properties 3 Value' | |
] | |
download_df = df[columns_to_include] | |
# Save filtered DataFrame as CSV file | |
output_file = "filtered_output.csv" | |
download_df.to_csv(output_file, index=False) | |
return df, output_file | |
# Define the main block for the interface | |
with gr.Blocks() as demo: | |
with gr.Tab("CSV Viewer"): | |
with gr.Row(): | |
file_input = gr.File(label="Upload CSV") | |
supplier_input = gr.Dropdown(choices=["", "Supplier 1", "Supplier 2", "Supplier 3", "Supplier 4", "Supplier 5"], label="Select Supplier") | |
load_button = gr.Button("Load Data") | |
with gr.Row(): | |
output_df = gr.DataFrame() | |
output_file = gr.File(label="Download Filtered CSV") | |
# Bind the function to inputs and outputs using the button | |
load_button.click(fn=display_csv, inputs=[file_input, supplier_input], outputs=[output_df, output_file]) | |
# You can add more tabs here with different functions | |
# Run the interface | |
demo.launch() |