Spaces:
Sleeping
Sleeping
| # app.py | |
| import streamlit as st | |
| import matplotlib.pyplot as plt | |
| import random | |
| from reportlab.lib.pagesizes import A4 | |
| from reportlab.pdfgen import canvas | |
| # ----------------- PDF Generator ----------------- | |
| def generate_pdf(inputs, risk): | |
| file_path = "CivilSync_Report.pdf" | |
| c = canvas.Canvas(file_path, pagesize=A4) | |
| c.setFont("Helvetica", 12) | |
| c.drawString(100, 800, "CivilSync - AI Construction Report") | |
| c.drawString(100, 780, f"Site: {inputs['length']}m x {inputs['width']}m") | |
| c.drawString(100, 760, f"Deadline: {inputs['deadline']}") | |
| c.drawString(100, 740, f"Delay Risk: {risk:.2%}") | |
| c.drawString(100, 720, "Contract Terms:") | |
| text = c.beginText(100, 700) | |
| for line in inputs['contract'].split('\n'): | |
| text.textLine(line) | |
| c.drawText(text) | |
| c.save() | |
| return file_path | |
| # ----------------- Streamlit UI ----------------- | |
| st.title("CivilSync ποΈ - AI Construction Assistant") | |
| st.sidebar.header("Project Info") | |
| length = st.sidebar.number_input("Site Length (m)", 10.0, 200.0, 50.0) | |
| width = st.sidebar.number_input("Site Width (m)", 10.0, 200.0, 30.0) | |
| deadline = st.sidebar.date_input("Project Deadline") | |
| contract = st.sidebar.text_area("Contract Clauses") | |
| if st.sidebar.button("Run AI Analysis"): | |
| delay_risk = random.uniform(0.1, 0.9) | |
| st.subheader("π Project Analysis") | |
| st.write(f"π Estimated Delay Risk: **{delay_risk:.2%}**") | |
| # Dummy Gantt Chart | |
| fig, ax = plt.subplots() | |
| ax.barh(["Foundation", "Frame", "Roof"], [10, 20, 5]) | |
| ax.set_title("Project Gantt Chart") | |
| st.pyplot(fig) | |
| # Dummy Site Layout | |
| fig2, ax2 = plt.subplots() | |
| ax2.plot([0, length, length, 0, 0], [0, 0, width, width, 0], label="Boundary") | |
| ax2.set_title("Site Layout") | |
| st.pyplot(fig2) | |
| # Generate PDF | |
| inputs = {"length": length, "width": width, "deadline": deadline, "contract": contract} | |
| pdf_path = generate_pdf(inputs, delay_risk) | |
| with open(pdf_path, "rb") as f: | |
| st.download_button("π Download AI Report", f, file_name="CivilSync_Report.pdf") |