Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1143,38 +1143,36 @@ Only output valid JSON with no comments or code fences."""
|
|
| 1143 |
|
| 1144 |
updated_report_html = str(soup)
|
| 1145 |
|
| 1146 |
-
#
|
| 1147 |
-
|
| 1148 |
-
|
| 1149 |
-
|
| 1150 |
-
|
| 1151 |
-
|
| 1152 |
-
If any new inline citations (e.g., [x]) have been introduced that are not in the original reference table,
|
| 1153 |
-
generate an updated References Summary Table as valid HTML. Output only the updated reference table HTML with no explanations.
|
| 1154 |
-
Updated Report HTML:\n{updated_report_html}"""
|
| 1155 |
)
|
| 1156 |
-
|
| 1157 |
-
updated_refs =
|
|
|
|
| 1158 |
|
| 1159 |
-
if updated_refs:
|
| 1160 |
soup_updated = BeautifulSoup(updated_report_html, "html.parser")
|
| 1161 |
-
ref_heading = soup_updated.find(lambda tag: tag.name in ["h1", "h2", "h3", "h4"] and "
|
| 1162 |
if ref_heading:
|
| 1163 |
next_sibling = ref_heading.find_next_sibling()
|
| 1164 |
if next_sibling:
|
| 1165 |
try:
|
| 1166 |
new_ref_html = BeautifulSoup(updated_refs, "html.parser")
|
| 1167 |
next_sibling.replace_with(new_ref_html)
|
| 1168 |
-
logging.info("
|
| 1169 |
except Exception as e:
|
| 1170 |
-
logging.error("
|
| 1171 |
else:
|
| 1172 |
-
logging.info("
|
| 1173 |
updated_report_html = str(soup_updated)
|
| 1174 |
else:
|
| 1175 |
-
logging.info("
|
| 1176 |
else:
|
| 1177 |
-
logging.info("
|
| 1178 |
|
| 1179 |
global_summary = "Corrections Applied Based on User Request:\n" + "\n".join(corrections_summary)
|
| 1180 |
updated_qa = qa.strip() + "\n----------\n" + global_summary
|
|
|
|
| 1143 |
|
| 1144 |
updated_report_html = str(soup)
|
| 1145 |
|
| 1146 |
+
# Step 5 (and 6): Update the reference table if needed.
|
| 1147 |
+
prompt_refs = (
|
| 1148 |
+
f"\nYou are a technical editor.\n\n"
|
| 1149 |
+
"Review the following updated report HTML. If any new inline citations (e.g., [x]) have been added that are not in the original reference table,\n"
|
| 1150 |
+
"generate an updated Reference Summary Table as valid HTML. Output only the updated table without any additional comments.\n\n"
|
| 1151 |
+
f"Updated Report HTML:\n{updated_report_html}"
|
|
|
|
|
|
|
|
|
|
| 1152 |
)
|
| 1153 |
+
# Increase token limit to 1500 for this call
|
| 1154 |
+
updated_refs = llm_call(prompt=prompt_refs, model="o3-mini", temperature=0, max_tokens_param=1500)
|
| 1155 |
+
updated_refs = updated_refs.strip().strip("```").strip()
|
| 1156 |
|
| 1157 |
+
if updated_refs and not updated_refs.lower().startswith("error: empty response"):
|
| 1158 |
soup_updated = BeautifulSoup(updated_report_html, "html.parser")
|
| 1159 |
+
ref_heading = soup_updated.find(lambda tag: tag.name in ["h1", "h2", "h3", "h4"] and "reference summary table" in tag.get_text(strip=True).lower())
|
| 1160 |
if ref_heading:
|
| 1161 |
next_sibling = ref_heading.find_next_sibling()
|
| 1162 |
if next_sibling:
|
| 1163 |
try:
|
| 1164 |
new_ref_html = BeautifulSoup(updated_refs, "html.parser")
|
| 1165 |
next_sibling.replace_with(new_ref_html)
|
| 1166 |
+
logging.info("fine_tune_report: Reference table updated successfully.")
|
| 1167 |
except Exception as e:
|
| 1168 |
+
logging.error("fine_tune_report: Error updating reference table: %s", e)
|
| 1169 |
else:
|
| 1170 |
+
logging.info("fine_tune_report: No sibling after reference heading; skipping reference update.")
|
| 1171 |
updated_report_html = str(soup_updated)
|
| 1172 |
else:
|
| 1173 |
+
logging.info("fine_tune_report: No reference table heading found; reference update skipped.")
|
| 1174 |
else:
|
| 1175 |
+
logging.info("fine_tune_report: No valid updated reference table returned; leaving unchanged.")
|
| 1176 |
|
| 1177 |
global_summary = "Corrections Applied Based on User Request:\n" + "\n".join(corrections_summary)
|
| 1178 |
updated_qa = qa.strip() + "\n----------\n" + global_summary
|