Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
import os
|
3 |
import time
|
4 |
import json
|
|
|
5 |
from openai import OpenAI
|
6 |
|
7 |
# Configuration
|
@@ -67,19 +68,20 @@ if st.session_state.tech_messages and st.session_state.tech_messages[-1]["role"]
|
|
67 |
reply_content = message.content[0].text.value.strip()
|
68 |
st.session_state.tech_messages.append({"role": "assistant", "content": reply_content})
|
69 |
|
70 |
-
# Try to parse response as JSON
|
71 |
try:
|
72 |
-
|
|
|
|
|
|
|
73 |
if isinstance(results, list):
|
74 |
for item in results:
|
75 |
st.markdown(f"### 📄 {item.get('drawing_number')} ({item.get('discipline')})")
|
76 |
st.markdown(f"**Summary:** {item.get('summary')}")
|
77 |
|
78 |
-
# Single image (keyword match)
|
79 |
if "image" in item:
|
80 |
st.image(item["image"], use_column_width=True)
|
81 |
|
82 |
-
# Multiple image pages
|
83 |
elif "images" in item:
|
84 |
for img in item["images"]:
|
85 |
st.image(img, use_column_width=True)
|
|
|
2 |
import os
|
3 |
import time
|
4 |
import json
|
5 |
+
import re
|
6 |
from openai import OpenAI
|
7 |
|
8 |
# Configuration
|
|
|
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 |
st.markdown(f"### 📄 {item.get('drawing_number')} ({item.get('discipline')})")
|
80 |
st.markdown(f"**Summary:** {item.get('summary')}")
|
81 |
|
|
|
82 |
if "image" in item:
|
83 |
st.image(item["image"], use_column_width=True)
|
84 |
|
|
|
85 |
elif "images" in item:
|
86 |
for img in item["images"]:
|
87 |
st.image(img, use_column_width=True)
|