aquibmoin commited on
Commit
a18637e
·
verified ·
1 Parent(s): cb31dc6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -35
app.py CHANGED
@@ -196,7 +196,7 @@ def generate_data_insights(user_input, exoplanet_data, max_tokens=500, temperatu
196
  def export_to_word(response_content):
197
  doc = Document()
198
 
199
- # Add a title
200
  doc.add_heading('AI Generated SCDD', 0)
201
 
202
  # Split the response by sections (### is used to mark sections)
@@ -204,32 +204,8 @@ def export_to_word(response_content):
204
 
205
  for section in sections:
206
  if section.strip():
207
- # Check for subsections based on section titles
208
- if section.startswith('Science Objectives'):
209
- doc.add_heading('Science Objectives', level=1)
210
- objectives = section.split('\n')[1:]
211
- for objective in objectives:
212
- if objective.strip().startswith('1.') or objective.strip().startswith('-'):
213
- doc.add_paragraph(objective.strip(), style='List Number')
214
- elif section.startswith('Physical Parameters'):
215
- doc.add_heading('Physical Parameters', level=1)
216
- params = section.split('\n')[1:]
217
- for param in params:
218
- if param.strip():
219
- doc.add_paragraph(param.strip(), style='Normal')
220
- elif section.startswith('Observables'):
221
- doc.add_heading('Observables', level=1)
222
- observables = section.split('\n')[1:]
223
- for observable in observables:
224
- if observable.strip():
225
- doc.add_paragraph(observable.strip(), style='Normal')
226
- elif section.startswith('Description of Desired Observations'):
227
- doc.add_heading('Description of Desired Observations', level=1)
228
- observations = section.split('\n')[1:]
229
- for obs in observations:
230
- if obs.strip().startswith('1.') or obs.strip().startswith('-'):
231
- doc.add_paragraph(obs.strip(), style='List Number')
232
- elif section.startswith('Technical Requirements Table'):
233
  doc.add_heading('Technical Requirements Table', level=1)
234
  # Extract the table part from the section
235
  table_lines = section.split('\n')[2:]
@@ -245,13 +221,10 @@ def export_to_word(response_content):
245
  cell.text = cell_text.strip()
246
  # Apply text wrapping for each cell
247
  cell._element.get_or_add_tcPr().append(parse_xml(r'<w:tcW w:w="2500" w:type="pct" ' + nsdecls('w') + '/>'))
248
- elif section.startswith('ADS References'):
249
- doc.add_heading('ADS References', level=1)
250
- references = section.split('\n')[1:]
251
- for reference in references:
252
- if reference.strip():
253
- doc.add_paragraph(reference.strip(), style='Normal')
254
-
255
  # Save the document to a temporary file
256
  temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".docx")
257
  doc.save(temp_file.name)
@@ -390,7 +363,7 @@ iface = gr.Interface(
390
  gr.HTML(label="Miro"),
391
  gr.HTML(label="Generate Mind Map on Mapify")
392
  ],
393
- title="ExosAI - NASA SMD SCDD AI Assistant [version-0.7a]",
394
  description="ExosAI is an AI-powered assistant for generating and visualising HWO Science Cases",
395
  )
396
 
 
196
  def export_to_word(response_content):
197
  doc = Document()
198
 
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 by sections (### is used to mark sections)
 
204
 
205
  for section in sections:
206
  if section.strip():
207
+ # Only handle the "Technical Requirements Table" section with proper formatting
208
+ if section.startswith('Technical Requirements Table'):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  doc.add_heading('Technical Requirements Table', level=1)
210
  # Extract the table part from the section
211
  table_lines = section.split('\n')[2:]
 
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
+ else:
225
+ # For any other section, add the text as-is (no special formatting)
226
+ doc.add_paragraph(section.strip())
227
+
 
 
 
228
  # Save the document to a temporary file
229
  temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".docx")
230
  doc.save(temp_file.name)
 
363
  gr.HTML(label="Miro"),
364
  gr.HTML(label="Generate Mind Map on Mapify")
365
  ],
366
+ title="ExosAI - NASA SMD SCDD AI Assistant [version-0.8a]",
367
  description="ExosAI is an AI-powered assistant for generating and visualising HWO Science Cases",
368
  )
369