Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -192,21 +192,32 @@ with tab2:
|
|
192 |
time.sleep(1)
|
193 |
messages = client.beta.threads.messages.list(thread_id=image_thread.id)
|
194 |
assistant_message = messages.data[0].content[0].text.value
|
|
|
|
|
195 |
cleaned_message = re.sub(r'\*\*(.*?)\*\*', r'<strong>\1</strong>', assistant_message)
|
196 |
cleaned_message = cleaned_message.replace("###", "<h4 style='margin-bottom: 10px;'>").replace("\n", "<br>")
|
197 |
-
|
|
|
|
|
198 |
lines = cleaned_message.split('<br>')
|
199 |
html_table = "<table class='spec-table'>"
|
|
|
200 |
for line in lines:
|
201 |
if '|' in line and '---' not in line and 'Year' not in line and 'Mileage' not in line:
|
202 |
cells = line.strip('|').split('|')
|
203 |
-
|
204 |
-
|
|
|
|
|
|
|
|
|
205 |
elif '|' not in line:
|
206 |
-
html_table += f"
|
207 |
html_table += "</table>"
|
208 |
-
cleaned_message = html_table
|
|
|
209 |
st.success("✅ Identification Complete")
|
210 |
st.markdown(f"<div class='car-spec-output'>{cleaned_message}</div>", unsafe_allow_html=True)
|
|
|
211 |
except Exception as e:
|
212 |
-
st.error(f"❌ Error during image analysis: {str(e)}")
|
|
|
192 |
time.sleep(1)
|
193 |
messages = client.beta.threads.messages.list(thread_id=image_thread.id)
|
194 |
assistant_message = messages.data[0].content[0].text.value
|
195 |
+
|
196 |
+
# Clean base message
|
197 |
cleaned_message = re.sub(r'\*\*(.*?)\*\*', r'<strong>\1</strong>', assistant_message)
|
198 |
cleaned_message = cleaned_message.replace("###", "<h4 style='margin-bottom: 10px;'>").replace("\n", "<br>")
|
199 |
+
|
200 |
+
# Table builder (only if valid Markdown table found)
|
201 |
+
if '|' in cleaned_message and cleaned_message.count('|') > 2:
|
202 |
lines = cleaned_message.split('<br>')
|
203 |
html_table = "<table class='spec-table'>"
|
204 |
+
has_table = False
|
205 |
for line in lines:
|
206 |
if '|' in line and '---' not in line and 'Year' not in line and 'Mileage' not in line:
|
207 |
cells = line.strip('|').split('|')
|
208 |
+
if len(cells) >= 2:
|
209 |
+
has_table = True
|
210 |
+
row_html = '<tr>' + ''.join(f'<td>{cell.strip()}</td>' for cell in cells) + '</tr>'
|
211 |
+
html_table += row_html
|
212 |
+
elif '|' not in line and has_table:
|
213 |
+
html_table += "</table><p>" + line + "</p><table class='spec-table'>"
|
214 |
elif '|' not in line:
|
215 |
+
html_table += f"<p>{line}</p>"
|
216 |
html_table += "</table>"
|
217 |
+
cleaned_message = html_table if has_table else cleaned_message
|
218 |
+
|
219 |
st.success("✅ Identification Complete")
|
220 |
st.markdown(f"<div class='car-spec-output'>{cleaned_message}</div>", unsafe_allow_html=True)
|
221 |
+
|
222 |
except Exception as e:
|
223 |
+
st.error(f"❌ Error during image analysis: {str(e)}")
|