leadingbridge commited on
Commit
9880a63
1 Parent(s): 34dad03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -7
app.py CHANGED
@@ -1,19 +1,40 @@
1
  import gradio as gr
2
  import pandas as pd
3
 
4
- def display_csv(file):
5
  # Read the CSV file
6
  df = pd.read_csv(file.name)
7
- # Return the DataFrame to Gradio for display
8
- return df
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- # Create a Gradio interface
 
 
 
 
 
11
  interface = gr.Interface(
12
  fn=display_csv,
13
- inputs="file",
14
- outputs="dataframe",
 
 
 
15
  title="CSV Viewer",
16
- description="Upload a CSV file and view its contents."
17
  )
18
 
19
  # Run the interface
 
1
  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
+ # If no supplier is selected or blank option is chosen
20
+ else:
21
+ pass # No filtering is applied, show all data
22
 
23
+ # Save the filtered DataFrame as a CSV file and return both the DataFrame and the CSV file path
24
+ output_file = "filtered_output.csv"
25
+ df.to_csv(output_file, index=False)
26
+ return df, output_file
27
+
28
+ # Create a Gradio interface with dropdown for supplier selection
29
  interface = gr.Interface(
30
  fn=display_csv,
31
+ inputs=[
32
+ "file",
33
+ gr.Dropdown(choices=["", "Supplier 1", "Supplier 2", "Supplier 3", "Supplier 4", "Supplier 5"], label="Select Supplier", value="")
34
+ ],
35
+ outputs=["dataframe", "file"],
36
  title="CSV Viewer",
37
+ description="Upload a CSV file, optionally select a supplier for specific Vendor filtering, view the contents, and download the file."
38
  )
39
 
40
  # Run the interface