import gradio as gr import pandas as pd def display_csv(file, supplier): # Read the CSV file df = pd.read_csv(file.name) # Filter DataFrame based on selected supplier if supplier == "Supplier 3": df = df[df['Vendor'].isin(["Seed", "EverColor"])] elif supplier == "Supplier 2": df = df[df['Vendor'].isin(["Candy Magic", "OLENS", "Fairy", "Shobido"])] elif supplier == "Supplier 4": df = df[df['Vendor'] == "Geo Medical"] elif supplier == "Supplier 5": df = df[df['Vendor'] == "Ann365"] elif supplier == "Supplier 1": df = df[~df['Vendor'].isin(["Seed", "EverColor", "Candy Magic", "OLENS", "Fairy", "Shobido", "Geo Medical", "Ann365"])] else: pass # No filtering is applied, show all data # Display the full DataFrame display_df = df.copy() # Select specific columns to include in the output CSV 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 the filtered DataFrame with selected columns as a CSV file output_file = "filtered_output.csv" download_df.to_csv(output_file, index=False) return display_df, output_file # Create a Gradio interface with dropdown for supplier selection interface = gr.Interface( fn=display_csv, inputs=[ "file", gr.Dropdown(choices=["", "Supplier 1", "Supplier 2", "Supplier 3", "Supplier 4", "Supplier 5"], label="Select Supplier", value="") ], outputs=["dataframe", "file"], title="CSV Viewer", description="Upload a CSV file, optionally select a supplier for specific Vendor filtering, view the full contents on screen, and download a file with selected columns." ) # Run the interface interface.launch()