Guiyom commited on
Commit
fc071dc
·
verified ·
1 Parent(s): b9b8e62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -305,7 +305,7 @@ Please output a JSON object with exactly two keys (no extra commentary):
305
  except Exception as e:
306
  logging.error(f"Error processing chunk {idx}: {e}. Raw result: {chunk_result}")
307
 
308
- # --- Post-process the report to update the reference table ---
309
  references_prompt = f"""Review the following report HTML.
310
  If any new inline citations (formatted as [x] where x is a number) have been introduced
311
  that are not yet included in the references table at the end of the report,
@@ -317,8 +317,21 @@ Report HTML:
317
  """
318
  updated_references = openai_call(prompt=references_prompt, model="o3-mini", max_tokens_param=1000, temperature=0.5)
319
  updated_references = updated_references.strip().strip("```")
320
- # Append the updated reference table at the very end of the report.
321
- updated_report_html += "\n" + updated_references
 
 
 
 
 
 
 
 
 
 
 
 
 
322
 
323
  summary_text = "Summary of Fine-Tuning Improvements:\n" + "\n".join(improvements_summary)
324
  global_summary = "Combined Chunk Improvement Guidelines:\n" + "\n".join(all_guidelines)
 
305
  except Exception as e:
306
  logging.error(f"Error processing chunk {idx}: {e}. Raw result: {chunk_result}")
307
 
308
+ # --- Post-process the report to update the reference table without appending extra content ---
309
  references_prompt = f"""Review the following report HTML.
310
  If any new inline citations (formatted as [x] where x is a number) have been introduced
311
  that are not yet included in the references table at the end of the report,
 
317
  """
318
  updated_references = openai_call(prompt=references_prompt, model="o3-mini", max_tokens_param=1000, temperature=0.5)
319
  updated_references = updated_references.strip().strip("```")
320
+
321
+ # Instead of appending, check if a references section exists and replace its content.
322
+ soup_updated = BeautifulSoup(updated_report_html, "html.parser")
323
+ ref_heading = soup_updated.find(lambda tag: tag.name == "h1" and "Reference Summary Table" in tag.get_text())
324
+ if ref_heading:
325
+ # Find the next sibling (which should be the references table or container)
326
+ next_sibling = ref_heading.find_next_sibling()
327
+ if next_sibling:
328
+ new_ref_html = BeautifulSoup(updated_references, "html.parser")
329
+ next_sibling.replace_with(new_ref_html)
330
+ # Update the working HTML string
331
+ updated_report_html = str(soup_updated)
332
+ else:
333
+ # If no reference section is found, do nothing.
334
+ logging.info("No existing reference table found; skipping reference replacement.")
335
 
336
  summary_text = "Summary of Fine-Tuning Improvements:\n" + "\n".join(improvements_summary)
337
  global_summary = "Combined Chunk Improvement Guidelines:\n" + "\n".join(all_guidelines)