Update app.py
Browse files
app.py
CHANGED
|
@@ -1736,14 +1736,16 @@ def reports_page():
|
|
| 1736 |
st.header("π Reports β Classification & Full Geotechnical")
|
| 1737 |
site = st.session_state["sites"][st.session_state["active_site"]]
|
| 1738 |
|
| 1739 |
-
#
|
| 1740 |
-
|
|
|
|
|
|
|
| 1741 |
if site.get("classifier_decision"):
|
| 1742 |
st.markdown("You have a saved classification for this site.")
|
| 1743 |
if st.button("Generate Classification PDF"):
|
| 1744 |
fname = f"classification_{site['Site Name'].replace(' ','_')}.pdf"
|
| 1745 |
|
| 1746 |
-
# Collect references
|
| 1747 |
refs = []
|
| 1748 |
if "rag_history" in st.session_state and site.get("Site ID") in st.session_state["rag_history"]:
|
| 1749 |
for h in st.session_state["rag_history"][site["Site ID"]]:
|
|
@@ -1756,12 +1758,14 @@ def reports_page():
|
|
| 1756 |
build_classification_pdf(site, site.get("classifier_decision"), buffer)
|
| 1757 |
buffer.seek(0)
|
| 1758 |
|
| 1759 |
-
st.download_button("Download Classification PDF", buffer, file_name=fname, mime="application/pdf")
|
| 1760 |
else:
|
| 1761 |
st.info("No classification saved for this site yet. Use the Classifier page.")
|
| 1762 |
|
| 1763 |
-
#
|
| 1764 |
-
|
|
|
|
|
|
|
| 1765 |
with st.form(key="report_quick_form"):
|
| 1766 |
cols = st.columns([2, 1, 1])
|
| 1767 |
cols[0].markdown("**Parameter**")
|
|
@@ -1781,10 +1785,12 @@ def reports_page():
|
|
| 1781 |
for fld, _ in REPORT_FIELDS:
|
| 1782 |
val = inputs.get(fld, "").strip()
|
| 1783 |
site[fld] = val if val != "" else "Not provided"
|
| 1784 |
-
st.success("Saved quick report values to active site.")
|
| 1785 |
|
| 1786 |
-
#
|
| 1787 |
-
|
|
|
|
|
|
|
| 1788 |
if st.button("Ask GeoMate (generate analysis & recommendations)"):
|
| 1789 |
context = {
|
| 1790 |
"site_name": site.get("Site Name"),
|
|
@@ -1808,7 +1814,7 @@ def reports_page():
|
|
| 1808 |
st.markdown("**GeoMate analysis**")
|
| 1809 |
st.markdown(resp)
|
| 1810 |
|
| 1811 |
-
#
|
| 1812 |
matches = re.findall(r"\[\[([A-Za-z0-9 _/-]+):\s*([0-9.+-eE]+)\s*([A-Za-z%\/]*)\]\]", resp)
|
| 1813 |
for m in matches:
|
| 1814 |
field, val, unit = m[0].strip(), m[1].strip(), m[2].strip()
|
|
@@ -1820,55 +1826,35 @@ def reports_page():
|
|
| 1820 |
site["Relative Compaction"] = f"{val} {unit}"
|
| 1821 |
|
| 1822 |
site["LLM_Report_Text"] = resp
|
| 1823 |
-
st.success("LLM analysis saved to site under 'LLM_Report_Text'.")
|
| 1824 |
|
| 1825 |
-
#
|
|
|
|
|
|
|
| 1826 |
st.markdown("---")
|
| 1827 |
-
st.subheader("Full Geotechnical Report
|
| 1828 |
-
if st.button("Start Report Chatbot"):
|
| 1829 |
-
st.session_state["sites"][st.session_state["active_site"]]["report_convo_state"] = 0
|
| 1830 |
-
st.rerun()
|
| 1831 |
-
|
| 1832 |
-
state = site.get("report_convo_state", -1)
|
| 1833 |
-
if state >= 0:
|
| 1834 |
-
st.markdown("Chatbot will ask for missing fields. You can answer or type 'skip' to leave blank.")
|
| 1835 |
-
show_table = [(f, site.get(f, "Not provided")) for f, _ in REPORT_FIELDS]
|
| 1836 |
-
st.table(show_table)
|
| 1837 |
-
|
| 1838 |
-
if state < len(REPORT_FIELDS):
|
| 1839 |
-
field, unit = REPORT_FIELDS[state]
|
| 1840 |
-
ans = st.text_input(f"GeoMate β Please provide '{field}' ({unit})", key=f"report_in_{state}")
|
| 1841 |
-
c1, c2 = st.columns([1, 1])
|
| 1842 |
-
with c1:
|
| 1843 |
-
if st.button("Submit", key=f"report_submit_{state}"):
|
| 1844 |
-
site[field] = ans.strip() if ans.strip() not in ("skip", "don't know", "dont know", "na", "n/a", "") else "Not provided"
|
| 1845 |
-
site["report_convo_state"] = state + 1
|
| 1846 |
-
st.rerun()
|
| 1847 |
-
with c2:
|
| 1848 |
-
if st.button("Skip", key=f"report_skip_{state}"):
|
| 1849 |
-
site[field] = "Not provided"
|
| 1850 |
-
site["report_convo_state"] = state + 1
|
| 1851 |
-
st.rerun()
|
| 1852 |
-
else:
|
| 1853 |
-
st.success("All report questions asked. You can generate the full report now.")
|
| 1854 |
-
ext_ref_text = st.text_area("Optional: External references (one per line)", value="")
|
| 1855 |
-
ext_refs = [r.strip() for r in ext_ref_text.splitlines() if r.strip()]
|
| 1856 |
|
| 1857 |
-
|
| 1858 |
-
|
| 1859 |
-
|
| 1860 |
-
|
| 1861 |
-
|
| 1862 |
-
|
| 1863 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1864 |
|
| 1865 |
-
|
| 1866 |
-
|
|
|
|
| 1867 |
|
| 1868 |
-
|
|
|
|
| 1869 |
|
| 1870 |
-
|
| 1871 |
-
|
| 1872 |
|
| 1873 |
# 8) Page router
|
| 1874 |
if "page" not in st.session_state:
|
|
|
|
| 1736 |
st.header("π Reports β Classification & Full Geotechnical")
|
| 1737 |
site = st.session_state["sites"][st.session_state["active_site"]]
|
| 1738 |
|
| 1739 |
+
# =====================================================
|
| 1740 |
+
# Classification Report
|
| 1741 |
+
# =====================================================
|
| 1742 |
+
st.subheader("π Classification-only Report")
|
| 1743 |
if site.get("classifier_decision"):
|
| 1744 |
st.markdown("You have a saved classification for this site.")
|
| 1745 |
if st.button("Generate Classification PDF"):
|
| 1746 |
fname = f"classification_{site['Site Name'].replace(' ','_')}.pdf"
|
| 1747 |
|
| 1748 |
+
# Collect references from rag_history
|
| 1749 |
refs = []
|
| 1750 |
if "rag_history" in st.session_state and site.get("Site ID") in st.session_state["rag_history"]:
|
| 1751 |
for h in st.session_state["rag_history"][site["Site ID"]]:
|
|
|
|
| 1758 |
build_classification_pdf(site, site.get("classifier_decision"), buffer)
|
| 1759 |
buffer.seek(0)
|
| 1760 |
|
| 1761 |
+
st.download_button("β¬οΈ Download Classification PDF", buffer, file_name=fname, mime="application/pdf")
|
| 1762 |
else:
|
| 1763 |
st.info("No classification saved for this site yet. Use the Classifier page.")
|
| 1764 |
|
| 1765 |
+
# =====================================================
|
| 1766 |
+
# Quick Report Form
|
| 1767 |
+
# =====================================================
|
| 1768 |
+
st.markdown("### βοΈ Quick report form (edit values and request LLM analysis)")
|
| 1769 |
with st.form(key="report_quick_form"):
|
| 1770 |
cols = st.columns([2, 1, 1])
|
| 1771 |
cols[0].markdown("**Parameter**")
|
|
|
|
| 1785 |
for fld, _ in REPORT_FIELDS:
|
| 1786 |
val = inputs.get(fld, "").strip()
|
| 1787 |
site[fld] = val if val != "" else "Not provided"
|
| 1788 |
+
st.success("β
Saved quick report values to active site.")
|
| 1789 |
|
| 1790 |
+
# =====================================================
|
| 1791 |
+
# LLM Analysis (Humanized Report Text)
|
| 1792 |
+
# =====================================================
|
| 1793 |
+
st.markdown("#### π€ LLM-powered analysis")
|
| 1794 |
if st.button("Ask GeoMate (generate analysis & recommendations)"):
|
| 1795 |
context = {
|
| 1796 |
"site_name": site.get("Site Name"),
|
|
|
|
| 1814 |
st.markdown("**GeoMate analysis**")
|
| 1815 |
st.markdown(resp)
|
| 1816 |
|
| 1817 |
+
# Extract structured values from [[FIELD: value unit]]
|
| 1818 |
matches = re.findall(r"\[\[([A-Za-z0-9 _/-]+):\s*([0-9.+-eE]+)\s*([A-Za-z%\/]*)\]\]", resp)
|
| 1819 |
for m in matches:
|
| 1820 |
field, val, unit = m[0].strip(), m[1].strip(), m[2].strip()
|
|
|
|
| 1826 |
site["Relative Compaction"] = f"{val} {unit}"
|
| 1827 |
|
| 1828 |
site["LLM_Report_Text"] = resp
|
| 1829 |
+
st.success("β
LLM analysis saved to site under 'LLM_Report_Text'.")
|
| 1830 |
|
| 1831 |
+
# =====================================================
|
| 1832 |
+
# Full Geotechnical Report
|
| 1833 |
+
# =====================================================
|
| 1834 |
st.markdown("---")
|
| 1835 |
+
st.subheader("π Full Geotechnical Report")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1836 |
|
| 1837 |
+
ext_ref_text = st.text_area("Optional: External references (one per line)", value="")
|
| 1838 |
+
ext_refs = [r.strip() for r in ext_ref_text.splitlines() if r.strip()]
|
| 1839 |
+
|
| 1840 |
+
# Add FAISS / rag references
|
| 1841 |
+
faiss_refs = []
|
| 1842 |
+
if "rag_history" in st.session_state and site.get("Site ID") in st.session_state["rag_history"]:
|
| 1843 |
+
for h in st.session_state["rag_history"][site["Site ID"]]:
|
| 1844 |
+
if h["who"] == "bot" and "[ref:" in h["text"]:
|
| 1845 |
+
for m in re.findall(r"\[ref:([^\]]+)\]", h["text"]):
|
| 1846 |
+
faiss_refs.append(m)
|
| 1847 |
+
all_refs = list(set(ext_refs + faiss_refs))
|
| 1848 |
|
| 1849 |
+
if st.button("Generate Full Geotechnical Report PDF"):
|
| 1850 |
+
outname = f"Full_Geotech_Report_{site.get('Site Name','site')}.pdf"
|
| 1851 |
+
mapimg = site.get("map_snapshot")
|
| 1852 |
|
| 1853 |
+
# β
Classification results also included inside full report
|
| 1854 |
+
build_full_geotech_pdf(site, outname, include_map_image=mapimg, ext_refs=all_refs)
|
| 1855 |
|
| 1856 |
+
with open(outname, "rb") as f:
|
| 1857 |
+
st.download_button("β¬οΈ Download Full Geotechnical Report", f, file_name=outname, mime="application/pdf")
|
| 1858 |
|
| 1859 |
# 8) Page router
|
| 1860 |
if "page" not in st.session_state:
|