bgamazay commited on
Commit
13836f6
·
verified ·
1 Parent(s): 4928504

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -7
app.py CHANGED
@@ -64,6 +64,16 @@ def read_csv_from_hub(file_name: str) -> pd.DataFrame:
64
  f"Original error: {e}"
65
  )
66
 
 
 
 
 
 
 
 
 
 
 
67
  def _normalize(col: str) -> str:
68
  return re.sub(r"[^a-z0-9]", "", col.strip().lower())
69
 
@@ -102,17 +112,30 @@ def month_abbrev_to_full(abbrev: str) -> Optional[str]:
102
 
103
  def render_date_from_test_date(value: str) -> str:
104
  """
105
- Accepts 'Oct 2025', 'Feb 2025' and returns 'October 2025', 'February 2025'.
106
- Returns '' if it can’t parse.
 
 
107
  """
108
  if not isinstance(value, str):
109
  return ""
110
  s = value.strip()
 
 
111
  m = re.match(r"^([A-Za-z]+)\s+(\d{4})$", s)
112
- if not m:
113
- return ""
114
- month_full = month_abbrev_to_full(m.group(1))
115
- return f"{month_full} {m.group(2)}" if month_full else ""
 
 
 
 
 
 
 
 
 
116
 
117
  def smart_capitalize(text):
118
  """Capitalize first letter only if not already; leave rest unchanged."""
@@ -344,7 +367,7 @@ def create_label_single_pass(background_image, model_data, final_size=(520, 728)
344
  energy_value = float(model_data.get('energy', 0.0))
345
  except Exception:
346
  energy_value = 0.0
347
- energy_text = f"{energy_value:.2f}"
348
  energy_bbox = draw.textbbox((0, 0), energy_text, font=energy_font)
349
  energy_text_width = energy_bbox[2] - energy_bbox[0]
350
  draw.text((energy_x - energy_text_width, energy_y), energy_text, font=energy_font, fill="black")
 
64
  f"Original error: {e}"
65
  )
66
 
67
+ def format_with_commas(value) -> str:
68
+ """
69
+ Format numeric values with commas and two decimals.
70
+ Example: 12345.678 -> '12,345.68'
71
+ """
72
+ try:
73
+ return f"{float(value):,.2f}"
74
+ except Exception:
75
+ return str(value)
76
+
77
  def _normalize(col: str) -> str:
78
  return re.sub(r"[^a-z0-9]", "", col.strip().lower())
79
 
 
112
 
113
  def render_date_from_test_date(value: str) -> str:
114
  """
115
+ Accepts formats:
116
+ - 'Oct 2025'
117
+ - 'Dec 25' (2-digit year)
118
+ Returns 'October 2025' or 'December 2025'.
119
  """
120
  if not isinstance(value, str):
121
  return ""
122
  s = value.strip()
123
+
124
+ # Case 1: 'Oct 2025'
125
  m = re.match(r"^([A-Za-z]+)\s+(\d{4})$", s)
126
+ if m:
127
+ month_full = month_abbrev_to_full(m.group(1))
128
+ return f"{month_full} {m.group(2)}" if month_full else ""
129
+
130
+ # Case 2: 'Dec 25' (map 25 -> 2025)
131
+ m2 = re.match(r"^([A-Za-z]+)\s+(\d{2})$", s)
132
+ if m2:
133
+ month_full = month_abbrev_to_full(m2.group(1))
134
+ year_full = f"20{m2.group(2)}"
135
+ return f"{month_full} {year_full}" if month_full else ""
136
+
137
+ return ""
138
+
139
 
140
  def smart_capitalize(text):
141
  """Capitalize first letter only if not already; leave rest unchanged."""
 
367
  energy_value = float(model_data.get('energy', 0.0))
368
  except Exception:
369
  energy_value = 0.0
370
+ energy_text = format_with_commas(energy_value)
371
  energy_bbox = draw.textbbox((0, 0), energy_text, font=energy_font)
372
  energy_text_width = energy_bbox[2] - energy_bbox[0]
373
  draw.text((energy_x - energy_text_width, energy_y), energy_text, font=energy_font, fill="black")