leadingbridge commited on
Commit
e433620
·
verified ·
1 Parent(s): 32acb11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -25
app.py CHANGED
@@ -1,23 +1,4 @@
1
- import gradio as gr
2
- import pandas as pd
3
- from datetime import datetime
4
- import pytz
5
-
6
- # Updated Gradio app for YunExpress with new header mappings and hyperlinks
7
-
8
- def process_file(file):
9
- file_name = file.name.lower()
10
- try:
11
- if file_name.endswith(('.xls', '.xlsx', '.xlsm')):
12
- # Read data from the "YunExpress" sheet
13
- df = pd.read_excel(file.name, sheet_name="YunExpress")
14
- else:
15
- return f"Unsupported file format: {file_name}", None
16
- except Exception as e:
17
- return f"Error reading file: {e}", None
18
-
19
- # New output headers as requested
20
- output_headers = [
21
  "CustomerOrderNo.", "RoutingCode", "Trackingnumber", "AdditionalServices",
22
  "ShipmentProtectionPlusService", "SignatureService", "VatNumber", "EoriNumber",
23
  "IossCode", "CountryCode", "Name", "CertificateCode", "Company", "Street", "City",
@@ -61,16 +42,16 @@ def process_file(file):
61
  if "Shipping Province" in df.columns:
62
  output_df["Province/State"] = df["Shipping Province"]
63
 
64
- # 6. ZipCode with US 4-digit padding using leading apostrophe
65
  if "Shipping ZIP" in df.columns:
66
  output_df["ZipCode"] = df["Shipping ZIP"].astype(str)
67
  # 7. CountryCode
68
  if "Shipping Country Code" in df.columns:
69
  output_df["CountryCode"] = df["Shipping Country Code"]
70
- # Pad US 4-digit Zips with apostrophe to preserve leading zero in Excel
71
  zip_str = output_df["ZipCode"].fillna("")
72
- mask_us_zip = (output_df.get("CountryCode", "") == "US") & zip_str.str.match(r'^\d{4}$')
73
- output_df.loc[mask_us_zip, "ZipCode"] = "'" + zip_str.str.zfill(5)
74
 
75
  # 8. phone
76
  if "Shipping Address Phone" in df.columns:
@@ -86,15 +67,20 @@ def process_file(file):
86
 
87
  # 11. Fixed defaults and conditional RoutingCode
88
  mask = output_df["CustomerOrderNo."].notna() & (output_df["CustomerOrderNo."] != "")
 
89
  mask_norway = mask & (output_df["CountryCode"] == "NO")
90
  mask_other = mask & (output_df["CountryCode"] != "NO")
 
91
  output_df.loc[mask_other, "RoutingCode"] = "HKTHZXR"
92
  output_df.loc[mask_norway, "RoutingCode"] = "HK-ASS-PF"
 
93
  output_df.loc[mask, "UnitPrice1"] = 2
94
  output_df.loc[mask, "CurrencyCode"] = "USD"
95
  output_df.loc[mask, "ItemDescription1"] = "Eye Cosmetic Accessories"
96
  output_df.loc[mask, "UnitWeight1"] = 0.02
 
97
  output_df.loc[mask, "ForeignItemDescription1"] = "Eye Cosmetic Accessories"
 
98
  EU_COUNTRIES = {"AT","BE","BG","CY","CZ","DE","DK","EE","ES","FI",
99
  "FR","HR","HU","IE","IT","LT","LU","LV","MT","NL",
100
  "PL","PT","RO","SE","SI","SK","GR"}
@@ -145,4 +131,4 @@ with gr.Blocks(title="Shipping - YunExpress") as demo:
145
  """
146
  )
147
 
148
- demo.launch()
 
1
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  "CustomerOrderNo.", "RoutingCode", "Trackingnumber", "AdditionalServices",
3
  "ShipmentProtectionPlusService", "SignatureService", "VatNumber", "EoriNumber",
4
  "IossCode", "CountryCode", "Name", "CertificateCode", "Company", "Street", "City",
 
42
  if "Shipping Province" in df.columns:
43
  output_df["Province/State"] = df["Shipping Province"]
44
 
45
+ # 6. ZipCode with US 4-digit padding
46
  if "Shipping ZIP" in df.columns:
47
  output_df["ZipCode"] = df["Shipping ZIP"].astype(str)
48
  # 7. CountryCode
49
  if "Shipping Country Code" in df.columns:
50
  output_df["CountryCode"] = df["Shipping Country Code"]
51
+ # Pad US 4-digit Zips
52
  zip_str = output_df["ZipCode"].fillna("")
53
+ mask_us_zip = (output_df.get("CountryCode", "")=="US") & zip_str.str.match(r'^\d{4}$')
54
+ output_df.loc[mask_us_zip, "ZipCode"] = zip_str.str.zfill(5)
55
 
56
  # 8. phone
57
  if "Shipping Address Phone" in df.columns:
 
67
 
68
  # 11. Fixed defaults and conditional RoutingCode
69
  mask = output_df["CustomerOrderNo."].notna() & (output_df["CustomerOrderNo."] != "")
70
+ # Norway code
71
  mask_norway = mask & (output_df["CountryCode"] == "NO")
72
  mask_other = mask & (output_df["CountryCode"] != "NO")
73
+ # RoutingCode assignments
74
  output_df.loc[mask_other, "RoutingCode"] = "HKTHZXR"
75
  output_df.loc[mask_norway, "RoutingCode"] = "HK-ASS-PF"
76
+ # Other fixed values
77
  output_df.loc[mask, "UnitPrice1"] = 2
78
  output_df.loc[mask, "CurrencyCode"] = "USD"
79
  output_df.loc[mask, "ItemDescription1"] = "Eye Cosmetic Accessories"
80
  output_df.loc[mask, "UnitWeight1"] = 0.02
81
+ # ForeignItemDescription1
82
  output_df.loc[mask, "ForeignItemDescription1"] = "Eye Cosmetic Accessories"
83
+ # EU AdditionalServices
84
  EU_COUNTRIES = {"AT","BE","BG","CY","CZ","DE","DK","EE","ES","FI",
85
  "FR","HR","HU","IE","IT","LT","LU","LV","MT","NL",
86
  "PL","PT","RO","SE","SI","SK","GR"}
 
131
  """
132
  )
133
 
134
+ demo.launch()