IAMTFRMZA commited on
Commit
dc07f4a
Β·
verified Β·
1 Parent(s): d4f41a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -25
app.py CHANGED
@@ -5,7 +5,7 @@ import json
5
  import re
6
  from openai import OpenAI
7
 
8
- # Configuration
9
  st.set_page_config(page_title="Forrestdale Drawing Viewer", layout="wide")
10
  st.title("πŸ“ Forrestdale Technical Drawing Assistant")
11
 
@@ -25,17 +25,15 @@ if "tech_thread_id" not in st.session_state:
25
  if "tech_messages" not in st.session_state:
26
  st.session_state.tech_messages = []
27
 
28
- # Prompt input
29
  prompt = st.chat_input("Ask about plans, drawings or components (e.g. Show me all electrical plans)")
30
  if prompt:
31
  st.session_state.tech_messages.append({"role": "user", "content": prompt})
32
 
33
- # Display assistant messages
34
  for msg in st.session_state.tech_messages:
35
  with st.chat_message(msg["role"]):
36
  st.markdown(msg["content"])
37
 
38
- # Trigger assistant
39
  if st.session_state.tech_messages and st.session_state.tech_messages[-1]["role"] == "user":
40
  with st.spinner("⏳ Fetching results from assistant..."):
41
  try:
@@ -68,33 +66,28 @@ if st.session_state.tech_messages and st.session_state.tech_messages[-1]["role"]
68
  reply_content = message.content[0].text.value.strip()
69
  st.session_state.tech_messages.append({"role": "assistant", "content": reply_content})
70
 
71
- # Try to parse response as JSON block (```json ... ```)
72
  try:
73
  match = re.search(r"```json\s*(.*?)```", reply_content, re.DOTALL)
74
  json_str = match.group(1) if match else reply_content
75
  results = json.loads(json_str)
76
 
77
  if isinstance(results, list):
78
- for item in results:
79
- drawing_number = item.get("drawing_number")
80
- discipline = item.get("discipline")
81
- summary = item.get("summary")
82
- images = item.get("images", [])
83
- single_image = item.get("image")
84
- question = item.get("question", None)
85
-
86
- with st.container(border=True):
87
- st.markdown(f"### πŸ—‚οΈ {drawing_number} ({discipline})")
88
- st.markdown(f"**Summary:** {summary}")
89
-
90
- with st.expander("πŸ“‚ View Drawing Details"):
91
- if question:
92
- st.markdown(f"**Question Match:** {question}")
93
- if single_image:
94
- st.image(single_image, caption=drawing_number)
95
- elif images:
96
- for i, img in enumerate(images, start=1):
97
- st.image(img, caption=f"{drawing_number} – Page {i}")
98
  except Exception as parse_error:
99
  st.warning("🟑 Could not parse assistant response as JSON.")
100
  break
 
5
  import re
6
  from openai import OpenAI
7
 
8
+ # Basic config
9
  st.set_page_config(page_title="Forrestdale Drawing Viewer", layout="wide")
10
  st.title("πŸ“ Forrestdale Technical Drawing Assistant")
11
 
 
25
  if "tech_messages" not in st.session_state:
26
  st.session_state.tech_messages = []
27
 
 
28
  prompt = st.chat_input("Ask about plans, drawings or components (e.g. Show me all electrical plans)")
29
  if prompt:
30
  st.session_state.tech_messages.append({"role": "user", "content": prompt})
31
 
 
32
  for msg in st.session_state.tech_messages:
33
  with st.chat_message(msg["role"]):
34
  st.markdown(msg["content"])
35
 
36
+ # Fetch assistant reply
37
  if st.session_state.tech_messages and st.session_state.tech_messages[-1]["role"] == "user":
38
  with st.spinner("⏳ Fetching results from assistant..."):
39
  try:
 
66
  reply_content = message.content[0].text.value.strip()
67
  st.session_state.tech_messages.append({"role": "assistant", "content": reply_content})
68
 
 
69
  try:
70
  match = re.search(r"```json\s*(.*?)```", reply_content, re.DOTALL)
71
  json_str = match.group(1) if match else reply_content
72
  results = json.loads(json_str)
73
 
74
  if isinstance(results, list):
75
+ cols = st.columns(4)
76
+ for idx, item in enumerate(results):
77
+ with cols[idx % 4]:
78
+ with st.container(border=True):
79
+ st.markdown(f"### πŸ“ {item.get('drawing_number')} ({item.get('discipline')})", help=item.get("summary"))
80
+ st.caption(item.get("summary"))
81
+
82
+ with st.expander("πŸ“‚ View Drawing Details"):
83
+ if item.get("question"):
84
+ st.markdown(f"**Question Match:** {item.get('question')}")
85
+ if item.get("image"):
86
+ st.image(item.get("image"), caption=item.get("drawing_number"))
87
+ elif item.get("images"):
88
+ for i, img in enumerate(item["images"]):
89
+ if img.startswith("http"):
90
+ st.image(img, caption=f"{item['drawing_number']} – Page {i+1}")
 
 
 
 
91
  except Exception as parse_error:
92
  st.warning("🟑 Could not parse assistant response as JSON.")
93
  break