File size: 2,104 Bytes
34dad03
 
 
9880a63
34dad03
9d3fa20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa2dcad
9d3fa20
 
 
fa2dcad
 
 
9d3fa20
 
9880a63
fa2dcad
9d3fa20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9880a63
9d3fa20
34dad03
 
9d3fa20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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()