Spaces:
Running
Running
leadingbridge
commited on
Commit
•
fa2dcad
1
Parent(s):
9880a63
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import pandas as pd
|
|
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"])]
|
@@ -16,25 +16,41 @@ def display_csv(file, supplier):
|
|
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 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
output_file = "filtered_output.csv"
|
25 |
-
|
26 |
-
return
|
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
|
38 |
)
|
39 |
|
40 |
# Run the interface
|
|
|
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"])]
|
|
|
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
|