-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
63 lines (46 loc) · 1.73 KB
/
ui.py
File metadata and controls
63 lines (46 loc) · 1.73 KB
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
57
58
59
60
61
62
63
import streamlit as st
import requests
API_URL = "https://ddr-ai-system.onrender.com/generate-ddr"
st.title("DDR Generator")
inspection = st.file_uploader("Inspection report", type="pdf")
thermal = st.file_uploader("Thermal report", type="pdf")
if st.button("Generate DDR"):
if not inspection or not thermal:
st.error("Both files are required.")
st.stop()
files = {
"inspection_report": (inspection.name, inspection, "application/pdf"),
"thermal_report": (thermal.name, thermal, "application/pdf"),
}
try:
with st.spinner("Generating DDR report... This may take 1–2 minutes"):
resp = requests.post(
API_URL,
files=files,
timeout=300 # increased timeout
)
except requests.exceptions.Timeout:
st.error("The server took too long to respond. Please try again.")
st.stop()
except requests.exceptions.RequestException as e:
st.error(f"Connection error: {e}")
st.stop()
if resp.status_code != 200:
st.error(f"Server error: {resp.text}")
st.stop()
data = resp.json()
extracted = data.get("extracted", {})
report = data.get("report", {})
st.subheader("Extracted Text")
st.write(extracted.get("inspection_text", "No inspection text found"))
st.write(extracted.get("thermal_text", "No thermal text found"))
st.subheader("Images")
images = extracted.get("images", [])
if images:
cols = st.columns(3) # display images in grid
for i, img in enumerate(images):
cols[i % 3].image(img, use_container_width=True)
else:
st.info("No images extracted.")
st.subheader("DDR Report")
st.json(report)