Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -199,20 +199,23 @@ def export_to_word(response_content):
|
|
199 |
# Add a title (optional, you can remove this if not needed)
|
200 |
doc.add_heading('AI Generated SCDD', 0)
|
201 |
|
202 |
-
# Split the response
|
203 |
sections = response_content.split('### ')
|
204 |
|
205 |
for section in sections:
|
206 |
if section.strip():
|
207 |
-
#
|
208 |
if section.startswith('Technical Requirements Table'):
|
209 |
doc.add_heading('Technical Requirements Table', level=1)
|
210 |
-
|
211 |
-
|
212 |
-
|
|
|
|
|
213 |
table_data = [line.split('|')[1:-1] for line in table_lines if '|' in line]
|
|
|
214 |
if table_data:
|
215 |
-
# Add
|
216 |
table = doc.add_table(rows=len(table_data), cols=len(table_data[0]))
|
217 |
table.style = 'Table Grid'
|
218 |
for i, row in enumerate(table_data):
|
@@ -221,15 +224,22 @@ def export_to_word(response_content):
|
|
221 |
cell.text = cell_text.strip()
|
222 |
# Apply text wrapping for each cell
|
223 |
cell._element.get_or_add_tcPr().append(parse_xml(r'<w:tcW w:w="2500" w:type="pct" ' + nsdecls('w') + '/>'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
elif section.startswith('ADS References'):
|
225 |
-
# Add the ADS References section as plain text
|
226 |
doc.add_heading('ADS References', level=1)
|
227 |
-
references = section.split('\n')[1:]
|
228 |
for reference in references:
|
229 |
if reference.strip():
|
230 |
doc.add_paragraph(reference.strip())
|
|
|
|
|
231 |
else:
|
232 |
-
# For any other section, add the text as-is (no special formatting)
|
233 |
doc.add_paragraph(section.strip())
|
234 |
|
235 |
# Save the document to a temporary file
|
|
|
199 |
# Add a title (optional, you can remove this if not needed)
|
200 |
doc.add_heading('AI Generated SCDD', 0)
|
201 |
|
202 |
+
# Split the response into sections based on ### headings
|
203 |
sections = response_content.split('### ')
|
204 |
|
205 |
for section in sections:
|
206 |
if section.strip():
|
207 |
+
# Handle the "Technical Requirements Table" separately with proper formatting
|
208 |
if section.startswith('Technical Requirements Table'):
|
209 |
doc.add_heading('Technical Requirements Table', level=1)
|
210 |
+
|
211 |
+
# Extract table lines
|
212 |
+
table_lines = section.split('\n')[2:] # Start after the heading line
|
213 |
+
|
214 |
+
# Check if it's an actual table (split lines by '|' symbol)
|
215 |
table_data = [line.split('|')[1:-1] for line in table_lines if '|' in line]
|
216 |
+
|
217 |
if table_data:
|
218 |
+
# Add table to the document
|
219 |
table = doc.add_table(rows=len(table_data), cols=len(table_data[0]))
|
220 |
table.style = 'Table Grid'
|
221 |
for i, row in enumerate(table_data):
|
|
|
224 |
cell.text = cell_text.strip()
|
225 |
# Apply text wrapping for each cell
|
226 |
cell._element.get_or_add_tcPr().append(parse_xml(r'<w:tcW w:w="2500" w:type="pct" ' + nsdecls('w') + '/>'))
|
227 |
+
|
228 |
+
# Process any paragraphs that follow the table
|
229 |
+
paragraph_after_table = '\n'.join([line for line in table_lines if '|' not in line and line.strip()])
|
230 |
+
if paragraph_after_table:
|
231 |
+
doc.add_paragraph(paragraph_after_table.strip())
|
232 |
+
|
233 |
+
# Handle the "ADS References" section
|
234 |
elif section.startswith('ADS References'):
|
|
|
235 |
doc.add_heading('ADS References', level=1)
|
236 |
+
references = section.split('\n')[1:] # Skip the heading
|
237 |
for reference in references:
|
238 |
if reference.strip():
|
239 |
doc.add_paragraph(reference.strip())
|
240 |
+
|
241 |
+
# Add all other sections as plain paragraphs
|
242 |
else:
|
|
|
243 |
doc.add_paragraph(section.strip())
|
244 |
|
245 |
# Save the document to a temporary file
|