annikwag commited on
Commit
48b1a6a
·
verified ·
1 Parent(s): cd592ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -63,15 +63,23 @@ def compute_title(metadata):
63
  # Load CRS lookup CSV and define a lookup function.
64
  crs_lookup = pd.read_csv("docStore/crs5_codes.csv") # Assumes columns: "code" and "new_crs_value"
65
  def lookup_crs_value(crs_key):
66
- row = crs_lookup[crs_lookup["code"] == crs_key]
 
 
 
67
  if not row.empty:
68
- # Convert to integer (drop decimals) and then to string.
69
- try:
70
- return str(int(float(row.iloc[0]["new_crs_value"])))
71
- except:
72
- return str(row.iloc[0]["new_crs_value"])
 
 
 
 
73
  return ""
74
 
 
75
  ###########################################
76
  # RAG Answer function (Change 1 & 2 & 3)
77
  ###########################################
 
63
  # Load CRS lookup CSV and define a lookup function.
64
  crs_lookup = pd.read_csv("docStore/crs5_codes.csv") # Assumes columns: "code" and "new_crs_value"
65
  def lookup_crs_value(crs_key):
66
+ # Ensure the input is a string and clean it.
67
+ key_clean = re.sub(r'\.0$', '', str(crs_key).strip())
68
+ # Compare against the CSV codes as strings.
69
+ row = crs_lookup[crs_lookup["code"].astype(str) == key_clean]
70
  if not row.empty:
71
+ # If a column named "new_crs_value" exists, use it.
72
+ if "new_crs_value" in row.columns:
73
+ try:
74
+ return re.sub(r'\.0$', '', str(int(float(row.iloc[0]["new_crs_value"]))))
75
+ except Exception:
76
+ return re.sub(r'\.0$', '', str(row.iloc[0]["new_crs_value"]))
77
+ else:
78
+ # Otherwise, use the "name" column as the lookup value.
79
+ return re.sub(r'\.0$', '', str(row.iloc[0]["name"]).strip())
80
  return ""
81
 
82
+
83
  ###########################################
84
  # RAG Answer function (Change 1 & 2 & 3)
85
  ###########################################