VaneshDev commited on
Commit
9f4b499
·
verified ·
1 Parent(s): 0b081d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -249,17 +249,19 @@ def generate_batch_pdf(records, batch_uid):
249
  c.setFont("Helvetica-Bold", 14)
250
  y = 760
251
 
252
- c.drawString(100, y, "Equipment Utilization Batch Report")
253
- y -= 30
254
- c.setFont("Helvetica", 12)
255
-
256
  for idx, record in enumerate(records, 1):
257
  # Start new page if near bottom
258
  if y < 100:
259
  c.showPage()
260
  c.setFont("Helvetica-Bold", 14)
261
  c.drawString(100, 770, "Equipment Utilization Batch Report")
262
- y = 740
 
 
 
 
 
 
263
  c.setFont("Helvetica", 12)
264
 
265
  c.drawString(100, y, f"Record {idx}: {record['Summary']['Equipment Name']}")
@@ -274,8 +276,8 @@ def generate_batch_pdf(records, batch_uid):
274
  c.showPage()
275
  c.setFont("Helvetica-Bold", 14)
276
  c.drawString(100, 770, "Equipment Utilization Batch Report")
277
- y = 740
278
  c.setFont("Helvetica", 12)
 
279
 
280
  y -= 10
281
  c.drawString(100, y, "-" * 50)
@@ -309,8 +311,9 @@ def manual_input(equipment, project, usage, idle, freq, cost, last, ai_suggestio
309
 
310
  def batch_upload(csv_file):
311
  try:
312
- if not csv_file:
313
- raise ValueError("Please upload a CSV file.")
 
314
  df = pd.read_csv(csv_file.name)
315
 
316
  required_columns = ['equipment_name', 'project_name', 'usage_hours', 'idle_hours', 'movement_frequency', 'cost_per_hour']
@@ -408,7 +411,7 @@ with gr.Blocks() as app:
408
  outputs=[csv_output, batch_pdf]
409
  )
410
  clear_btn.click(
411
- lambda: ("", None),
412
  None,
413
  [csv_file, csv_output, batch_pdf]
414
  )
 
249
  c.setFont("Helvetica-Bold", 14)
250
  y = 760
251
 
 
 
 
 
252
  for idx, record in enumerate(records, 1):
253
  # Start new page if near bottom
254
  if y < 100:
255
  c.showPage()
256
  c.setFont("Helvetica-Bold", 14)
257
  c.drawString(100, 770, "Equipment Utilization Batch Report")
258
+ c.setFont("Helvetica", 12)
259
+ y = 750
260
+
261
+ # Print title on first page or new page
262
+ if y == 760:
263
+ c.drawString(100, y, "Equipment Utilization Batch Report")
264
+ y -= 20
265
  c.setFont("Helvetica", 12)
266
 
267
  c.drawString(100, y, f"Record {idx}: {record['Summary']['Equipment Name']}")
 
276
  c.showPage()
277
  c.setFont("Helvetica-Bold", 14)
278
  c.drawString(100, 770, "Equipment Utilization Batch Report")
 
279
  c.setFont("Helvetica", 12)
280
+ y = 750
281
 
282
  y -= 10
283
  c.drawString(100, y, "-" * 50)
 
311
 
312
  def batch_upload(csv_file):
313
  try:
314
+ if csv_file is None:
315
+ return "", None # Gracefully handle cleared or empty input
316
+
317
  df = pd.read_csv(csv_file.name)
318
 
319
  required_columns = ['equipment_name', 'project_name', 'usage_hours', 'idle_hours', 'movement_frequency', 'cost_per_hour']
 
411
  outputs=[csv_output, batch_pdf]
412
  )
413
  clear_btn.click(
414
+ lambda: (None, "", None), # Reset file input, output markdown, and pdf file output
415
  None,
416
  [csv_file, csv_output, batch_pdf]
417
  )