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"])] # If no supplier is selected or blank option is chosen else: pass # No filtering is applied, show all data # Save the filtered DataFrame as a CSV file and return both the DataFrame and the CSV file path output_file = "filtered_output.csv" df.to_csv(output_file, index=False) return 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 contents, and download the file." ) # Run the interface interface.launch()