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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -25
app.py CHANGED
@@ -1,22 +1,28 @@
1
  import gradio as gr
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',
@@ -25,27 +31,36 @@ def display_csv(file, supplier):
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()
 
1
  import gradio as gr
2
  import pandas as pd
3
+ from datetime import datetime
4
+ import pytz # This library is used for timezone conversions
5
 
6
+ def display_csv(file, supplier, order_number):
7
  df = pd.read_csv(file.name)
8
+
9
  # Define supplier-specific filters
10
  vendor_filters = {
11
+ "Supplier 1": lambda df: df[~df['Vendor'].isin(["Seed", "EverColor", "Candy Magic", "OLENS", "Fairy", "Shobido", "Geo Medical", "Ann365", "Lenstown", "LensVery"])],
12
  "Supplier 2": lambda df: df[df['Vendor'].isin(["Candy Magic", "OLENS", "Fairy", "Shobido"])],
13
  "Supplier 3": lambda df: df[df['Vendor'].isin(["Seed", "EverColor"])],
14
+ "Supplier 4": lambda df: df[df['Vendor'] == "Geo Medical", "Lenstown"],
15
+ "Supplier 5": lambda df: df[df['Vendor'] == "Ann365", "LensVery"]
16
  }
17
+
18
+ # Apply supplier filter if selected
19
  if supplier and supplier in vendor_filters:
20
  df = vendor_filters[supplier](df)
21
+
22
+ # Filter based on order number
23
+ if order_number:
24
+ df = df[df['Order Number'] >= int(order_number)]
25
+
26
  # Specify columns for output
27
  columns_to_include = [
28
  'Order Number', 'Quantity', 'Product Title', 'Product Option Name',
 
31
  'Order Line item Properties 3 Value'
32
  ]
33
  download_df = df[columns_to_include]
34
+
35
+ # Get the current date in Hong Kong Time
36
+ hk_timezone = pytz.timezone("Asia/Hong_Kong")
37
+ current_date_hk = datetime.now(hk_timezone).strftime("%y%m%d")
38
+
39
+ # Set output file name based on the selected supplier
40
+ if supplier == "Supplier 1":
41
+ output_file = f"Leading Bridge Order {current_date_hk}.xlsx"
42
+ elif supplier == "Supplier 2":
43
+ output_file = f"Leading Bridge Order {current_date_hk}-Ammu.xlsx"
44
+ else:
45
+ output_file = "filtered_output.xlsx" # Default file name for other cases
46
+
47
+ # Save filtered DataFrame as Excel file
48
+ download_df.to_excel(output_file, index=False)
49
  return df, output_file
50
 
51
  # Define the main block for the interface
52
  with gr.Blocks() as demo:
53
+ with gr.Row():
54
+ file_input = gr.File(label="Upload CSV")
55
+ supplier_input = gr.Dropdown(choices=["", "Supplier 1", "Supplier 2", "Supplier 3", "Supplier 4", "Supplier 5"], label="Select Supplier")
56
+ order_number_input = gr.Number(label="Minimum Order Number", precision=0)
57
+ load_button = gr.Button("Load Data")
58
+ with gr.Row():
59
+ output_df = gr.DataFrame()
60
+ output_file = gr.File(label="Download Filtered CSV")
61
+
62
+ # Bind the function to inputs and outputs using the button
63
+ load_button.click(fn=display_csv, inputs=[file_input, supplier_input, order_number_input], outputs=[output_df, output_file])
 
 
64
 
65
  # Run the interface
66
  demo.launch()