File size: 1,575 Bytes
34dad03
 
 
9880a63
34dad03
 
9880a63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34dad03
9880a63
 
 
 
 
 
34dad03
 
9880a63
 
 
 
 
34dad03
9880a63
34dad03
 
 
 
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
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()