Update app.py
Browse files
app.py
CHANGED
|
@@ -921,4 +921,90 @@ def reports_ui():
|
|
| 921 |
if st.button("Generate Full Geotechnical Report (PDF)"):
|
| 922 |
with st.spinner("Building PDF..."):
|
| 923 |
pdf_bytes = build_full_report_pdf(site)
|
| 924 |
-
st.download_button("Download Report PDF", data=pdf_bytes, file_name=f"GeoMate_FullReport_{site.get('Site Name','site')}.pdf", mime="application/pdf")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 921 |
if st.button("Generate Full Geotechnical Report (PDF)"):
|
| 922 |
with st.spinner("Building PDF..."):
|
| 923 |
pdf_bytes = build_full_report_pdf(site)
|
| 924 |
+
st.download_button("Download Report PDF", data=pdf_bytes, file_name=f"GeoMate_FullReport_{site.get('Site Name','site')}.pdf", mime="application/pdf")
|
| 925 |
+
# -----------------------------
|
| 926 |
+
# --- GeoMate Ask (RAG chat) - placeholder
|
| 927 |
+
# -----------------------------
|
| 928 |
+
def rag_ui():
|
| 929 |
+
st.header("🤖 GeoMate Ask — RAG (placeholder)")
|
| 930 |
+
site = get_active_site()
|
| 931 |
+
if not site:
|
| 932 |
+
st.info("Create/select a site first.")
|
| 933 |
+
return
|
| 934 |
+
st.markdown("This RAG interface is wired as a placeholder. Connect your FAISS DB and LLM backend to enable retrieval and answers.")
|
| 935 |
+
q = st.text_input("Ask a geotechnical question (example: 'What foundation would you recommend for this site?')")
|
| 936 |
+
if st.button("Ask"):
|
| 937 |
+
user_q = q.strip()
|
| 938 |
+
if not user_q:
|
| 939 |
+
st.warning("Enter a question.")
|
| 940 |
+
return
|
| 941 |
+
# Save to site chat history
|
| 942 |
+
site.setdefault("chat_history", []).append(("user", user_q))
|
| 943 |
+
# Placeholder answer (you should call your LLM here)
|
| 944 |
+
answer = "Placeholder answer: connect your LLM / FAISS RAG backend to get a real answer. The system will use site data and retrieved documents."
|
| 945 |
+
site["chat_history"].append(("bot", answer))
|
| 946 |
+
save_active_site(site)
|
| 947 |
+
st.markdown(f"**GeoMate:** {answer}")
|
| 948 |
+
|
| 949 |
+
# -----------------------------
|
| 950 |
+
# --- Soil Recognizer (image classifier placeholder)
|
| 951 |
+
# -----------------------------
|
| 952 |
+
def soil_recognizer_ui():
|
| 953 |
+
st.header("🖼️ Soil Recognizer")
|
| 954 |
+
site = get_active_site()
|
| 955 |
+
if not site:
|
| 956 |
+
st.info("Create/select a site first.")
|
| 957 |
+
return
|
| 958 |
+
uploaded = st.file_uploader("Upload a soil photo (JPG/PNG)", type=["jpg","jpeg","png"])
|
| 959 |
+
if uploaded:
|
| 960 |
+
try:
|
| 961 |
+
im = Image.open(uploaded).convert("RGB")
|
| 962 |
+
st.image(im, caption="Uploaded image", use_column_width=True)
|
| 963 |
+
# placeholder classifier: average brightness to pick a class (toy)
|
| 964 |
+
arr = np.array(im.convert("L"))
|
| 965 |
+
mean = arr.mean()
|
| 966 |
+
if mean > 140:
|
| 967 |
+
pred = "Sand / Light soil"
|
| 968 |
+
elif mean > 80:
|
| 969 |
+
pred = "Silt"
|
| 970 |
+
else:
|
| 971 |
+
pred = "Clay / Dark soil"
|
| 972 |
+
st.success(f"Predicted soil type: {pred} (placeholder model)")
|
| 973 |
+
site["Soil Type (image)"] = pred
|
| 974 |
+
save_active_site(site)
|
| 975 |
+
except Exception as e:
|
| 976 |
+
st.error(f"Image processing failed: {e}")
|
| 977 |
+
|
| 978 |
+
# -----------------------------
|
| 979 |
+
# --- Main UI Router
|
| 980 |
+
# -----------------------------
|
| 981 |
+
def main_ui():
|
| 982 |
+
sidebar_ui()
|
| 983 |
+
page = ss.get("page", "Landing")
|
| 984 |
+
# use option_menu on sidebar to control as well
|
| 985 |
+
with st.sidebar:
|
| 986 |
+
choice = option_menu(None, ["Landing","Soil Recognizer","Soil Classifier","GSD Curve","Locator","GeoMate Ask","Reports"],
|
| 987 |
+
icons=["house","image","bar-chart","bar-chart-line","geo-alt","robot","file-earmark-text"], menu_icon="compass", default_index=0)
|
| 988 |
+
# sync page choice
|
| 989 |
+
ss["page"] = choice
|
| 990 |
+
page = ss["page"]
|
| 991 |
+
|
| 992 |
+
if page == "Landing":
|
| 993 |
+
landing_ui()
|
| 994 |
+
elif page == "Soil Recognizer":
|
| 995 |
+
soil_recognizer_ui()
|
| 996 |
+
elif page == "Soil Classifier":
|
| 997 |
+
soil_classifier_ui()
|
| 998 |
+
elif page == "GSD Curve":
|
| 999 |
+
gsd_curve_ui()
|
| 1000 |
+
elif page == "Locator":
|
| 1001 |
+
locator_ui()
|
| 1002 |
+
elif page == "GeoMate Ask":
|
| 1003 |
+
rag_ui()
|
| 1004 |
+
elif page == "Reports":
|
| 1005 |
+
reports_ui()
|
| 1006 |
+
else:
|
| 1007 |
+
st.write("Unknown page.")
|
| 1008 |
+
|
| 1009 |
+
if __name__ == "__main__":
|
| 1010 |
+
main_ui()
|