Preeeeet commited on
Commit
184d675
·
verified ·
1 Parent(s): 75be300

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -21
app.py CHANGED
@@ -141,11 +141,8 @@ def generate_report(image_items, job_details, compress_images, quality, progress
141
 
142
  # Header
143
  header = section.header
144
- # --- FIX START 1 ---
145
- # Original code: header_table = header.add_table(rows=1, cols=2, width=Inches(CONTENT_WIDTH_IN))
146
- header_table = header.add_table(rows=1, cols=2)
147
- header_table.width = Inches(CONTENT_WIDTH_IN)
148
- # --- FIX END 1 ---
149
  header_table.autofit = False
150
  set_table_fixed_layout(header_table)
151
  header_table.columns[0].width = Inches(2.5)
@@ -180,20 +177,18 @@ def generate_report(image_items, job_details, compress_images, quality, progress
180
 
181
  page_items = image_items[start:start + 2]
182
 
183
- # 2x2 table with borders
184
- # --- FIX START 2 ---
185
- # Original code: page_table = doc.add_table(rows=2, cols=2, width=Inches(CONTENT_WIDTH_IN))
186
  page_table = doc.add_table(rows=2, cols=2)
187
  page_table.width = Inches(CONTENT_WIDTH_IN)
188
- # --- FIX END 2 ---
189
  page_table.autofit = False
190
  set_table_fixed_layout(page_table)
191
- page_table.style = 'Table Grid' # borders ON
192
  page_table.alignment = WD_TABLE_ALIGNMENT.CENTER
193
 
194
  # Lock column widths and row heights
195
- page_table.columns[0].width = Inches(DESC_COL_IN) # 1 part
196
- page_table.columns[1].width = Inches(PHOTO_COL_IN) # 4 parts
197
  for r in page_table.rows:
198
  r.height = Inches(ROW_HEIGHT_IN)
199
  r.height_rule = WD_ROW_HEIGHT_RULE.EXACTLY
@@ -258,7 +253,6 @@ def generate_report(image_items, job_details, compress_images, quality, progress
258
  if num_images:
259
  progress_bar.progress(processed / num_images)
260
  else:
261
- # Empty row for last page single-item case (grid remains consistent)
262
  pass
263
 
264
  # Save DOCX
@@ -290,21 +284,18 @@ def generate_report(image_items, job_details, compress_images, quality, progress
290
  # --- STREAMLIT UI ---
291
  st.set_page_config(layout="centered", page_title="HKC Report Generator")
292
 
293
- # Session state
294
  if 'image_dict' not in st.session_state:
295
  st.session_state.image_dict = {}
296
 
297
  def reset_app():
298
  st.session_state.clear()
299
 
300
- # Header/logo
301
  if os.path.exists("logo.png"):
302
  st.image("logo.png", width=200)
303
 
304
  st.title("Photo Report Generator")
305
  st.markdown("---")
306
 
307
- # Sidebar
308
  with st.sidebar:
309
  st.header("1. Job Information")
310
  job_key = st.selectbox(
@@ -326,7 +317,6 @@ with st.sidebar:
326
  reset_app()
327
  st.rerun()
328
 
329
- # Main area
330
  st.header("Upload, Arrange, Rotate, and Describe Images")
331
  uploaded_files = st.file_uploader(
332
  "Upload all your photos here",
@@ -335,7 +325,6 @@ uploaded_files = st.file_uploader(
335
  key="file_uploader"
336
  )
337
 
338
- # Add newly uploaded files to session
339
  if uploaded_files:
340
  for file in uploaded_files:
341
  fid = getattr(file, "file_id", None) or f"{file.name}-{id(file)}"
@@ -348,7 +337,6 @@ if uploaded_files:
348
  'rotation': 0
349
  }
350
 
351
- # Display sortable/rotatable items
352
  if st.session_state.image_dict:
353
  st.info("Set the order, rotate if needed, then add descriptions. Exactly 2 photos per page (last page may have 1).")
354
  items = list(st.session_state.image_dict.items())
@@ -378,7 +366,6 @@ if st.session_state.image_dict:
378
  "Description", value=item_data.get('description', ''), key=f"desc_{fid}", height=120
379
  )
380
 
381
- # Generate
382
  if generate_button:
383
  if not job_details:
384
  st.error("Please select a job.")
@@ -394,7 +381,6 @@ if generate_button:
394
  )
395
  progress_bar.success("Report generated successfully!")
396
 
397
- # File name per dropdown + yymmdd
398
  date_str = datetime.now().strftime("%y%m%d")
399
  file_base = f"{job_key} - {date_str}"
400
 
 
141
 
142
  # Header
143
  header = section.header
144
+ # --- FIX 1: The header's add_table method REQUIRES the width argument directly ---
145
+ header_table = header.add_table(rows=1, cols=2, width=Inches(CONTENT_WIDTH_IN))
 
 
 
146
  header_table.autofit = False
147
  set_table_fixed_layout(header_table)
148
  header_table.columns[0].width = Inches(2.5)
 
177
 
178
  page_items = image_items[start:start + 2]
179
 
180
+ # --- FIX 2: The main document's add_table method does NOT accept the 'width' keyword ---
181
+ # So we create the table first, then set its width property.
 
182
  page_table = doc.add_table(rows=2, cols=2)
183
  page_table.width = Inches(CONTENT_WIDTH_IN)
 
184
  page_table.autofit = False
185
  set_table_fixed_layout(page_table)
186
+ page_table.style = 'Table Grid'
187
  page_table.alignment = WD_TABLE_ALIGNMENT.CENTER
188
 
189
  # Lock column widths and row heights
190
+ page_table.columns[0].width = Inches(DESC_COL_IN)
191
+ page_table.columns[1].width = Inches(PHOTO_COL_IN)
192
  for r in page_table.rows:
193
  r.height = Inches(ROW_HEIGHT_IN)
194
  r.height_rule = WD_ROW_HEIGHT_RULE.EXACTLY
 
253
  if num_images:
254
  progress_bar.progress(processed / num_images)
255
  else:
 
256
  pass
257
 
258
  # Save DOCX
 
284
  # --- STREAMLIT UI ---
285
  st.set_page_config(layout="centered", page_title="HKC Report Generator")
286
 
 
287
  if 'image_dict' not in st.session_state:
288
  st.session_state.image_dict = {}
289
 
290
  def reset_app():
291
  st.session_state.clear()
292
 
 
293
  if os.path.exists("logo.png"):
294
  st.image("logo.png", width=200)
295
 
296
  st.title("Photo Report Generator")
297
  st.markdown("---")
298
 
 
299
  with st.sidebar:
300
  st.header("1. Job Information")
301
  job_key = st.selectbox(
 
317
  reset_app()
318
  st.rerun()
319
 
 
320
  st.header("Upload, Arrange, Rotate, and Describe Images")
321
  uploaded_files = st.file_uploader(
322
  "Upload all your photos here",
 
325
  key="file_uploader"
326
  )
327
 
 
328
  if uploaded_files:
329
  for file in uploaded_files:
330
  fid = getattr(file, "file_id", None) or f"{file.name}-{id(file)}"
 
337
  'rotation': 0
338
  }
339
 
 
340
  if st.session_state.image_dict:
341
  st.info("Set the order, rotate if needed, then add descriptions. Exactly 2 photos per page (last page may have 1).")
342
  items = list(st.session_state.image_dict.items())
 
366
  "Description", value=item_data.get('description', ''), key=f"desc_{fid}", height=120
367
  )
368
 
 
369
  if generate_button:
370
  if not job_details:
371
  st.error("Please select a job.")
 
381
  )
382
  progress_bar.success("Report generated successfully!")
383
 
 
384
  date_str = datetime.now().strftime("%y%m%d")
385
  file_base = f"{job_key} - {date_str}"
386