Pavlo Kostianov commited on
Commit
a6bbf7e
Β·
1 Parent(s): 8d3574a

Update loader function to load whole Budget sheet and improve prompt

Browse files
Files changed (1) hide show
  1. app.py +22 -23
app.py CHANGED
@@ -25,24 +25,13 @@ df2_all = pd.read_excel(
25
  df1 = {}
26
  for sheet, raw_df in df1_all.items():
27
  if sheet == "Budget":
28
- # Special preprocess for Budget sheet
29
- budget_raw = pd.read_excel(
30
- os.path.join("data_source", "OC Onboarding Information.xlsx"),
31
- sheet_name="Budget",
32
- header=None
33
- )
34
- # Part 1: detailed breakdown (rows 3–20 with headers at row 3)
35
- budget_details = pd.read_excel(
36
  os.path.join("data_source", "OC Onboarding Information.xlsx"),
37
  sheet_name="Budget",
38
  header=2,
39
- nrows=17 # stop before totals
40
  )
41
- # Part 2: summary section (rows 21+)
42
- budget_summary = budget_raw.iloc[20:].reset_index(drop=True)
43
- # Add into df1 dict
44
- df1["Budget_Details"] = budget_details
45
- df1["Budget_Summary"] = budget_summary
46
  elif sheet == "Rooms per category":
47
  # use row 4 as header
48
  df1[sheet] = pd.read_excel(
@@ -76,14 +65,24 @@ for sheet, raw_df in df2_all.items():
76
  def get_schema_info():
77
  lines = ["Report 1 - OC Onboarding Information:"]
78
  for sheet, df in df1.items():
79
- lines.append(f"Sheet: {sheet}, Columns: {list(df.columns)}")
80
- sample = df.head(1).to_dict(orient="records")[0]
81
- lines.append(f"Example row: {sample}")
 
 
 
 
 
 
 
82
  lines.append("\nReport 2 - The Alex Ideas Report:")
83
  for sheet, df in df2.items():
84
  lines.append(f"Sheet: {sheet}, Columns: {list(df.columns)}")
85
- sample = df.head(1).to_dict(orient="records")[0]
86
- lines.append(f"Example row: {sample}")
 
 
 
87
  return "\n".join(lines)
88
 
89
  schema_info = get_schema_info()
@@ -127,19 +126,19 @@ If absolutely no relation to provided sheets, respond with:
127
 
128
  The reports are OC Onboarding Information and The Alex Ideas Report.
129
  OC Onboarding Information (df1) is the initial hotel data including a budget set by the hotel for the year.
130
- - "Budget_Details": line-item breakdown (channels, rates, revenue, etc.)
131
- - "Budget_Summary": summary rows (total occupancy, RevPar for each month, etc.)
132
  The Alex Ideas Report (df2) is the real reports about revenue of the hotel for the year.
133
 
134
- They have the following schema:
135
  {schema_info}
136
 
137
  The user asked:
138
  {message}
139
 
140
  Rules:
141
- - Use only pandas, df1, df2, and Python built-ins.
142
  - Do NOT write import statements (pandas is already imported as pd).
 
 
143
  - Always put the answer in a variable named `result`.
144
  - Return ONLY Python code, nothing else.
145
  - If multiple values are tied for the maximum, include all of them in a list.
 
25
  df1 = {}
26
  for sheet, raw_df in df1_all.items():
27
  if sheet == "Budget":
28
+ # Load rows 3–33 with headers at row 3
29
+ df1[sheet] = pd.read_excel(
 
 
 
 
 
 
30
  os.path.join("data_source", "OC Onboarding Information.xlsx"),
31
  sheet_name="Budget",
32
  header=2,
33
+ nrows=31 # rows 3–33 inclusive
34
  )
 
 
 
 
 
35
  elif sheet == "Rooms per category":
36
  # use row 4 as header
37
  df1[sheet] = pd.read_excel(
 
65
  def get_schema_info():
66
  lines = ["Report 1 - OC Onboarding Information:"]
67
  for sheet, df in df1.items():
68
+ if sheet == "Budget":
69
+ lines.append(f'Sheet: {sheet} (rows 3–33). This sheet contains the full hotel budget, including both detailed line items (by channel/segment) and summary metrics (total revenue, occupancy %, RevPAR, capacity).')
70
+ else:
71
+ lines.append(f"Sheet: {sheet}, Columns: {list(df.columns)}")
72
+ # Add one example row for context
73
+ try:
74
+ sample = df.head(1).to_dict(orient="records")[0]
75
+ lines.append(f"Example row: {sample}")
76
+ except Exception:
77
+ lines.append("Example row: [no data available]")
78
  lines.append("\nReport 2 - The Alex Ideas Report:")
79
  for sheet, df in df2.items():
80
  lines.append(f"Sheet: {sheet}, Columns: {list(df.columns)}")
81
+ try:
82
+ sample = df.head(1).to_dict(orient="records")[0]
83
+ lines.append(f"Example row: {sample}")
84
+ except Exception:
85
+ lines.append("Example row: [no data available]")
86
  return "\n".join(lines)
87
 
88
  schema_info = get_schema_info()
 
126
 
127
  The reports are OC Onboarding Information and The Alex Ideas Report.
128
  OC Onboarding Information (df1) is the initial hotel data including a budget set by the hotel for the year.
 
 
129
  The Alex Ideas Report (df2) is the real reports about revenue of the hotel for the year.
130
 
131
+ They have the following schema (sheet names, columns, and example rows, but Budget sheet is fully loaded):
132
  {schema_info}
133
 
134
  The user asked:
135
  {message}
136
 
137
  Rules:
138
+ - Use ONLY pandas, df1, df2, and Python built-ins.
139
  - Do NOT write import statements (pandas is already imported as pd).
140
+ - Access all dataframes ONLY as df1["SheetName"] or df2["SheetName"].
141
+ Never assign them to new variables like budget_df, property_df, etc.
142
  - Always put the answer in a variable named `result`.
143
  - Return ONLY Python code, nothing else.
144
  - If multiple values are tied for the maximum, include all of them in a list.