File size: 2,054 Bytes
ba463ce
 
17c0991
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2028431
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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")