leadingbridge commited on
Commit
9d3fa20
1 Parent(s): fa2dcad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -43
app.py CHANGED
@@ -2,56 +2,50 @@ import gradio as gr
2
  import pandas as pd
3
 
4
  def display_csv(file, supplier):
5
- # Read the CSV file
6
  df = pd.read_csv(file.name)
7
-
8
- # Filter DataFrame based on selected supplier
9
- if supplier == "Supplier 3":
10
- df = df[df['Vendor'].isin(["Seed", "EverColor"])]
11
- elif supplier == "Supplier 2":
12
- df = df[df['Vendor'].isin(["Candy Magic", "OLENS", "Fairy", "Shobido"])]
13
- elif supplier == "Supplier 4":
14
- df = df[df['Vendor'] == "Geo Medical"]
15
- elif supplier == "Supplier 5":
16
- df = df[df['Vendor'] == "Ann365"]
17
- elif supplier == "Supplier 1":
18
- df = df[~df['Vendor'].isin(["Seed", "EverColor", "Candy Magic", "OLENS", "Fairy", "Shobido", "Geo Medical", "Ann365"])]
19
- else:
20
- pass # No filtering is applied, show all data
21
-
22
- # Display the full DataFrame
23
- display_df = df.copy()
24
-
25
- # Select specific columns to include in the output CSV
26
  columns_to_include = [
27
- 'Order Number',
28
- 'Quantity',
29
- 'Product Title',
30
- 'Product Option Name',
31
- 'Product Option Value',
32
- 'Order Line item Properties 2 Name',
33
- 'Order Line item Properties 2 Value',
34
- 'Order Line item Properties 3 Name',
35
  'Order Line item Properties 3 Value'
36
  ]
37
  download_df = df[columns_to_include]
38
-
39
- # Save the filtered DataFrame with selected columns as a CSV file
40
  output_file = "filtered_output.csv"
41
  download_df.to_csv(output_file, index=False)
42
- return display_df, output_file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- # Create a Gradio interface with dropdown for supplier selection
45
- interface = gr.Interface(
46
- fn=display_csv,
47
- inputs=[
48
- "file",
49
- gr.Dropdown(choices=["", "Supplier 1", "Supplier 2", "Supplier 3", "Supplier 4", "Supplier 5"], label="Select Supplier", value="")
50
- ],
51
- outputs=["dataframe", "file"],
52
- title="CSV Viewer",
53
- 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."
54
- )
55
 
56
  # Run the interface
57
- interface.launch()
 
2
  import pandas as pd
3
 
4
  def display_csv(file, supplier):
 
5
  df = pd.read_csv(file.name)
6
+
7
+ # Define supplier-specific filters
8
+ vendor_filters = {
9
+ "Supplier 1": lambda df: df[~df['Vendor'].isin(["Seed", "EverColor", "Candy Magic", "OLENS", "Fairy", "Shobido", "Geo Medical", "Ann365"])],
10
+ "Supplier 2": lambda df: df[df['Vendor'].isin(["Candy Magic", "OLENS", "Fairy", "Shobido"])],
11
+ "Supplier 3": lambda df: df[df['Vendor'].isin(["Seed", "EverColor"])],
12
+ "Supplier 4": lambda df: df[df['Vendor'] == "Geo Medical"],
13
+ "Supplier 5": lambda df: df[df['Vendor'] == "Ann365"]
14
+ }
15
+
16
+ # Apply filter based on selected supplier
17
+ if supplier and supplier in vendor_filters:
18
+ df = vendor_filters[supplier](df)
19
+
20
+ # Specify columns for output
 
 
 
 
21
  columns_to_include = [
22
+ 'Order Number', 'Quantity', 'Product Title', 'Product Option Name',
23
+ 'Product Option Value', 'Order Line item Properties 2 Name',
24
+ 'Order Line item Properties 2 Value', 'Order Line item Properties 3 Name',
 
 
 
 
 
25
  'Order Line item Properties 3 Value'
26
  ]
27
  download_df = df[columns_to_include]
28
+
29
+ # Save filtered DataFrame as CSV file
30
  output_file = "filtered_output.csv"
31
  download_df.to_csv(output_file, index=False)
32
+ return df, output_file
33
+
34
+ # Define the main block for the interface
35
+ with gr.Blocks() as demo:
36
+ with gr.Tab("CSV Viewer"):
37
+ with gr.Row():
38
+ file_input = gr.File(label="Upload CSV")
39
+ supplier_input = gr.Dropdown(choices=["", "Supplier 1", "Supplier 2", "Supplier 3", "Supplier 4", "Supplier 5"], label="Select Supplier")
40
+ load_button = gr.Button("Load Data")
41
+ with gr.Row():
42
+ output_df = gr.DataFrame()
43
+ output_file = gr.File(label="Download Filtered CSV")
44
+
45
+ # Bind the function to inputs and outputs using the button
46
+ load_button.click(fn=display_csv, inputs=[file_input, supplier_input], outputs=[output_df, output_file])
47
 
48
+ # You can add more tabs here with different functions
 
 
 
 
 
 
 
 
 
 
49
 
50
  # Run the interface
51
+ demo.launch()