Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,13 +22,13 @@ if not OPENAI_API_KEY or not ASSISTANT_ID:
|
|
22 |
|
23 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
24 |
|
25 |
-
# ------------------ Map document titles to
|
26 |
DOCUMENT_FOLDER_MAP = {
|
27 |
"Tender 5 of 2024 - Forrestdale": "Schlager Group Pty Ltd - Tender 5 of 2024 - Forrestdale ~ Pavilion and External Works Part 1 of 2",
|
28 |
"Tender 5 of 2024 - Forrestdale Part 2": "Schlager Group Pty Ltd - Tender 5 of 2024 - Forrestdale ~ Pavilion and External Works Part 2 of 2",
|
29 |
"Armadale Forrestdale Methodology": "Armadale Forrestdale Methodology",
|
30 |
-
"22.146.DS Electrical Specification IFC Rev_0": "22.146.DS Electrical Specification IFC Rev_0",
|
31 |
"2302-FORRESTDALE SPORTING PAVILION-TECHNICAL SPECIFICATION": "2302-FORRESTDALE SPORTING PAVILION-TECHNICAL SPECIFICATION",
|
|
|
32 |
"Forrrestdale Community Hub Program 23-04-2025": "Forrrestdale Community Hub Program 23-04-2025",
|
33 |
"Landscape Specification - Forrestdale Community Hub_02": "Landscape Specification - Forrestdale Community Hub_02",
|
34 |
"Mechanical_Spec_-_Forrestdale Sporting Club Room IFC": "Mechanical_Spec_-_Forrestdale Sporting Club Room IFC",
|
@@ -100,14 +100,14 @@ with col2:
|
|
100 |
thread = client.beta.threads.create()
|
101 |
st.session_state.thread_id = thread.id
|
102 |
|
103 |
-
# Send user message
|
104 |
client.beta.threads.messages.create(
|
105 |
thread_id=st.session_state.thread_id,
|
106 |
role="user",
|
107 |
content=prompt
|
108 |
)
|
109 |
|
110 |
-
#
|
111 |
run = client.beta.threads.runs.create(
|
112 |
thread_id=st.session_state.thread_id,
|
113 |
assistant_id=ASSISTANT_ID
|
@@ -123,7 +123,7 @@ with col2:
|
|
123 |
break
|
124 |
time.sleep(1)
|
125 |
|
126 |
-
# Retrieve
|
127 |
messages = client.beta.threads.messages.list(thread_id=st.session_state.thread_id)
|
128 |
assistant_message = None
|
129 |
for message in reversed(messages.data):
|
@@ -133,23 +133,22 @@ with col2:
|
|
133 |
|
134 |
st.session_state.messages.append({"role": "assistant", "content": assistant_message})
|
135 |
|
136 |
-
# ✅ Extract
|
137 |
-
match = re.search(
|
138 |
-
r'https://raw\.githubusercontent\.com/AndrewLORTech/[^/]+/([^/]+)/\1_page_(\d{4})\.png',
|
139 |
-
assistant_message
|
140 |
-
)
|
141 |
if match:
|
142 |
-
|
143 |
-
page_num = match.group(2)
|
|
|
|
|
|
|
|
|
144 |
|
145 |
-
|
146 |
-
correct_folder = DOCUMENT_FOLDER_MAP.get(doc_display, doc_display)
|
147 |
-
correct_url = (
|
148 |
f"https://raw.githubusercontent.com/AndrewLORTech/c2ozschlaegerforrestdale/main/"
|
149 |
-
f"{
|
150 |
)
|
151 |
|
152 |
-
st.session_state.image_url =
|
153 |
st.session_state.image_updated = True
|
154 |
|
155 |
st.rerun()
|
|
|
22 |
|
23 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
24 |
|
25 |
+
# ------------------ Map document titles to GitHub folder names ------------------
|
26 |
DOCUMENT_FOLDER_MAP = {
|
27 |
"Tender 5 of 2024 - Forrestdale": "Schlager Group Pty Ltd - Tender 5 of 2024 - Forrestdale ~ Pavilion and External Works Part 1 of 2",
|
28 |
"Tender 5 of 2024 - Forrestdale Part 2": "Schlager Group Pty Ltd - Tender 5 of 2024 - Forrestdale ~ Pavilion and External Works Part 2 of 2",
|
29 |
"Armadale Forrestdale Methodology": "Armadale Forrestdale Methodology",
|
|
|
30 |
"2302-FORRESTDALE SPORTING PAVILION-TECHNICAL SPECIFICATION": "2302-FORRESTDALE SPORTING PAVILION-TECHNICAL SPECIFICATION",
|
31 |
+
"22.146.DS Electrical Specification IFC Rev_0": "22.146.DS Electrical Specification IFC Rev_0",
|
32 |
"Forrrestdale Community Hub Program 23-04-2025": "Forrrestdale Community Hub Program 23-04-2025",
|
33 |
"Landscape Specification - Forrestdale Community Hub_02": "Landscape Specification - Forrestdale Community Hub_02",
|
34 |
"Mechanical_Spec_-_Forrestdale Sporting Club Room IFC": "Mechanical_Spec_-_Forrestdale Sporting Club Room IFC",
|
|
|
100 |
thread = client.beta.threads.create()
|
101 |
st.session_state.thread_id = thread.id
|
102 |
|
103 |
+
# Send user message
|
104 |
client.beta.threads.messages.create(
|
105 |
thread_id=st.session_state.thread_id,
|
106 |
role="user",
|
107 |
content=prompt
|
108 |
)
|
109 |
|
110 |
+
# Run assistant
|
111 |
run = client.beta.threads.runs.create(
|
112 |
thread_id=st.session_state.thread_id,
|
113 |
assistant_id=ASSISTANT_ID
|
|
|
123 |
break
|
124 |
time.sleep(1)
|
125 |
|
126 |
+
# Retrieve assistant message
|
127 |
messages = client.beta.threads.messages.list(thread_id=st.session_state.thread_id)
|
128 |
assistant_message = None
|
129 |
for message in reversed(messages.data):
|
|
|
133 |
|
134 |
st.session_state.messages.append({"role": "assistant", "content": assistant_message})
|
135 |
|
136 |
+
# ✅ Extract folder + page number from "Document Reference" line
|
137 |
+
match = re.search(r'Document Reference:\s+(.+?),\s+Page\s+(\d+)', assistant_message)
|
|
|
|
|
|
|
138 |
if match:
|
139 |
+
doc_name_raw = match.group(1).strip()
|
140 |
+
page_num = int(match.group(2))
|
141 |
+
page_str = f"{page_num:04d}"
|
142 |
+
|
143 |
+
# Map to actual GitHub folder name
|
144 |
+
folder_name = DOCUMENT_FOLDER_MAP.get(doc_name_raw, doc_name_raw)
|
145 |
|
146 |
+
corrected_url = (
|
|
|
|
|
147 |
f"https://raw.githubusercontent.com/AndrewLORTech/c2ozschlaegerforrestdale/main/"
|
148 |
+
f"{folder_name}/{folder_name}_page_{page_str}.png"
|
149 |
)
|
150 |
|
151 |
+
st.session_state.image_url = corrected_url
|
152 |
st.session_state.image_updated = True
|
153 |
|
154 |
st.rerun()
|