Update app.py
Browse files
app.py
CHANGED
|
@@ -1810,6 +1810,7 @@ def rag_page():
|
|
| 1810 |
("Allowable Bearing (kPa)","kPa")
|
| 1811 |
]
|
| 1812 |
|
|
|
|
| 1813 |
def reports_page():
|
| 1814 |
st.header("📑 Reports — Classification & Full Geotechnical")
|
| 1815 |
site = st.session_state["sites"][st.session_state["active_site"]]
|
|
@@ -1847,64 +1848,66 @@ def reports_page():
|
|
| 1847 |
cols[1].markdown("**Value**")
|
| 1848 |
cols[2].markdown("**Unit / Notes**")
|
| 1849 |
|
| 1850 |
-
|
| 1851 |
-
|
| 1852 |
-
|
| 1853 |
-
|
| 1854 |
-
|
| 1855 |
-
|
| 1856 |
-
|
| 1857 |
-
|
| 1858 |
-
|
| 1859 |
-
|
| 1860 |
-
|
| 1861 |
-
|
| 1862 |
-
|
| 1863 |
-
|
| 1864 |
-
|
| 1865 |
|
| 1866 |
# LLM analysis button
|
| 1867 |
st.markdown("#### LLM-powered analysis")
|
| 1868 |
if st.button("Ask GeoMate (generate analysis & recommendations)"):
|
| 1869 |
-
|
| 1870 |
context = {
|
| 1871 |
-
|
| 1872 |
-
|
| 1873 |
-
|
| 1874 |
-
|
| 1875 |
-
|
| 1876 |
-
|
| 1877 |
-
|
| 1878 |
-
|
| 1879 |
}
|
| 1880 |
prompt = (
|
| 1881 |
-
|
| 1882 |
-
|
| 1883 |
-
|
| 1884 |
-
|
| 1885 |
-
|
| 1886 |
)
|
| 1887 |
-
|
| 1888 |
-
|
| 1889 |
-
|
| 1890 |
-
|
| 1891 |
-
|
| 1892 |
-
|
| 1893 |
-
|
| 1894 |
-
|
| 1895 |
-
|
| 1896 |
-
|
| 1897 |
-
|
| 1898 |
-
|
| 1899 |
-
|
| 1900 |
-
|
| 1901 |
-
|
| 1902 |
-
|
| 1903 |
-
|
| 1904 |
-
|
| 1905 |
-
|
| 1906 |
-
|
| 1907 |
-
|
|
|
|
|
|
|
| 1908 |
|
| 1909 |
st.markdown("---")
|
| 1910 |
st.subheader("Full Geotechnical Report (chatbot will gather missing fields)")
|
|
@@ -1913,8 +1916,8 @@ def reports_page():
|
|
| 1913 |
st.rerun()
|
| 1914 |
|
| 1915 |
# Conversational data collection
|
| 1916 |
-
state = site.get("report_convo_state",
|
| 1917 |
-
if
|
| 1918 |
st.markdown("Chatbot will ask for missing fields. You can answer or type 'skip' to leave blank.")
|
| 1919 |
# Show current known fields
|
| 1920 |
st.write("Current key parameters (live):")
|
|
@@ -1922,6 +1925,7 @@ def reports_page():
|
|
| 1922 |
for f,_ in REPORT_FIELDS:
|
| 1923 |
show_table.append((f, site.get(f, "Not provided")))
|
| 1924 |
st.table(show_table)
|
|
|
|
| 1925 |
# continue conversation step-by-step
|
| 1926 |
if state < len(REPORT_FIELDS):
|
| 1927 |
field, unit = REPORT_FIELDS[state]
|
|
@@ -1950,9 +1954,11 @@ def reports_page():
|
|
| 1950 |
outname = f"Full_Geotech_Report_{site.get('Site Name','site')}.pdf"
|
| 1951 |
# include map image bytes if available
|
| 1952 |
mapimg = site.get("map_snapshot")
|
| 1953 |
-
build_full_geotech_pdf
|
| 1954 |
-
|
| 1955 |
-
|
|
|
|
|
|
|
| 1956 |
|
| 1957 |
# 8) Page router
|
| 1958 |
if "page" not in st.session_state:
|
|
|
|
| 1810 |
("Allowable Bearing (kPa)","kPa")
|
| 1811 |
]
|
| 1812 |
|
| 1813 |
+
|
| 1814 |
def reports_page():
|
| 1815 |
st.header("📑 Reports — Classification & Full Geotechnical")
|
| 1816 |
site = st.session_state["sites"][st.session_state["active_site"]]
|
|
|
|
| 1848 |
cols[1].markdown("**Value**")
|
| 1849 |
cols[2].markdown("**Unit / Notes**")
|
| 1850 |
|
| 1851 |
+
# build inputs dynamically from REPORT_FIELDS
|
| 1852 |
+
inputs = {}
|
| 1853 |
+
for (fld, unit) in REPORT_FIELDS:
|
| 1854 |
+
c1, c2, c3 = st.columns([2,1,1])
|
| 1855 |
+
c1.markdown(f"**{fld}**")
|
| 1856 |
+
default_val = site.get(fld, "")
|
| 1857 |
+
inputs[fld] = c2.text_input(fld, value=str(default_val), label_visibility="collapsed", key=f"quick_{fld}")
|
| 1858 |
+
c3.markdown(unit)
|
| 1859 |
+
|
| 1860 |
+
submitted = st.form_submit_button("Save values to site")
|
| 1861 |
+
if submitted:
|
| 1862 |
+
for fld, _ in REPORT_FIELDS:
|
| 1863 |
+
val = inputs.get(fld, "").strip()
|
| 1864 |
+
site[fld] = val if val != "" else "Not provided"
|
| 1865 |
+
st.success("Saved quick report values to active site.")
|
| 1866 |
|
| 1867 |
# LLM analysis button
|
| 1868 |
st.markdown("#### LLM-powered analysis")
|
| 1869 |
if st.button("Ask GeoMate (generate analysis & recommendations)"):
|
| 1870 |
+
# prepare context for the LLM from the site
|
| 1871 |
context = {
|
| 1872 |
+
"site_name": site.get("Site Name"),
|
| 1873 |
+
"project": site.get("Project Name"),
|
| 1874 |
+
"site_summary": {
|
| 1875 |
+
"USCS": site.get("USCS"), "AASHTO": site.get("AASHTO"), "GI": site.get("GI"),
|
| 1876 |
+
"Soil Profile": site.get("Soil Profile"),
|
| 1877 |
+
"Key lab results": [r.get("sampleId") for r in site.get("Laboratory Results",[])]
|
| 1878 |
+
},
|
| 1879 |
+
"inputs": {fld: site.get(fld,"Not provided") for fld,_ in REPORT_FIELDS}
|
| 1880 |
}
|
| 1881 |
prompt = (
|
| 1882 |
+
"You are GeoMate AI, an engineering assistant. Given the following site context and "
|
| 1883 |
+
"engineering parameters (some may be 'Not provided'), produce:\n1) short executive summary, "
|
| 1884 |
+
"2) geotechnical interpretation (classification, key risks), 3) recommended remedial/improvement "
|
| 1885 |
+
"options and 4) short design notes. Provide any numeric outputs in the format [[FIELD: value unit]].\n\n"
|
| 1886 |
+
f"Context: {json.dumps(context)}\n\nAnswer concisely and professionally."
|
| 1887 |
)
|
| 1888 |
+
# NOTE: Assuming groq_generate is a function you have defined elsewhere
|
| 1889 |
+
# resp = groq_generate(prompt, model=st.session_state["llm_model"], max_tokens=600)
|
| 1890 |
+
resp = "This is a placeholder response for demonstration." # Placeholder
|
| 1891 |
+
|
| 1892 |
+
# display
|
| 1893 |
+
st.markdown("**GeoMate analysis**")
|
| 1894 |
+
st.markdown(resp)
|
| 1895 |
+
# try to extract numeric fields (same bracket format as elsewhere)
|
| 1896 |
+
matches = re.findall(r"\[\[([A-Za-z0-9 _/-]+):\s*([0-9.+-eE]+)\s*([A-Za-z%\/]*)\]\]", resp)
|
| 1897 |
+
for m in matches:
|
| 1898 |
+
field = m[0].strip()
|
| 1899 |
+
val = m[1].strip()
|
| 1900 |
+
unit = m[2].strip()
|
| 1901 |
+
# map likely field names:
|
| 1902 |
+
if "bearing" in field.lower():
|
| 1903 |
+
site["Load Bearing Capacity"] = f"{val} {unit}"
|
| 1904 |
+
elif "skin" in field.lower():
|
| 1905 |
+
site["Skin Shear Strength"] = f"{val} {unit}"
|
| 1906 |
+
elif "compaction" in field.lower():
|
| 1907 |
+
site["Relative Compaction"] = f"{val} {unit}"
|
| 1908 |
+
# store the analysis text so it can be included in the PDF later
|
| 1909 |
+
site["LLM_Report_Text"] = resp
|
| 1910 |
+
st.success("LLM analysis saved to site under 'LLM_Report_Text'.")
|
| 1911 |
|
| 1912 |
st.markdown("---")
|
| 1913 |
st.subheader("Full Geotechnical Report (chatbot will gather missing fields)")
|
|
|
|
| 1916 |
st.rerun()
|
| 1917 |
|
| 1918 |
# Conversational data collection
|
| 1919 |
+
state = site.get("report_convo_state", -1)
|
| 1920 |
+
if state >= 0:
|
| 1921 |
st.markdown("Chatbot will ask for missing fields. You can answer or type 'skip' to leave blank.")
|
| 1922 |
# Show current known fields
|
| 1923 |
st.write("Current key parameters (live):")
|
|
|
|
| 1925 |
for f,_ in REPORT_FIELDS:
|
| 1926 |
show_table.append((f, site.get(f, "Not provided")))
|
| 1927 |
st.table(show_table)
|
| 1928 |
+
|
| 1929 |
# continue conversation step-by-step
|
| 1930 |
if state < len(REPORT_FIELDS):
|
| 1931 |
field, unit = REPORT_FIELDS[state]
|
|
|
|
| 1954 |
outname = f"Full_Geotech_Report_{site.get('Site Name','site')}.pdf"
|
| 1955 |
# include map image bytes if available
|
| 1956 |
mapimg = site.get("map_snapshot")
|
| 1957 |
+
# NOTE: Assuming build_full_geotech_pdf is defined elsewhere
|
| 1958 |
+
# build_full_geotech_pdf(site, outname, include_map_image=mapimg, ext_refs=ext_refs)
|
| 1959 |
+
st.info("Placeholder for PDF generation.") # Placeholder
|
| 1960 |
+
# with open(outname, "rb") as f:
|
| 1961 |
+
# st.download_button("Download Full Geotechnical Report", f, file_name=outname, mime="application/pdf")
|
| 1962 |
|
| 1963 |
# 8) Page router
|
| 1964 |
if "page" not in st.session_state:
|