bakrianoo commited on
Commit
fc1df00
·
1 Parent(s): 4257826

fix styling section names

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -240,6 +240,21 @@ def generate_download_translated(download_format, article_title, article_summary
240
  f.write(content)
241
  return temp_path
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  # Add this function to update UI with sections from Wikipedia content
244
  def update_ui_with_sections(sections):
245
  """
@@ -260,11 +275,14 @@ def update_ui_with_sections(sections):
260
  section_title = list(sections.keys())[i]
261
  section_content = sections[section_title]
262
 
 
 
 
263
  # Make section textbox visible with content and label
264
  results.extend([
265
- gr.update(visible=True, value=section_content, label=f"Section: {section_title}"),
266
  gr.update(visible=True), # Translate button
267
- gr.update(visible=True, value="", label=f"Translation: {section_title}"), # Translation output
268
  gr.update(visible=False) # Debug button (hidden by default)
269
  ])
270
  else:
 
240
  f.write(content)
241
  return temp_path
242
 
243
+ def clean_section_title(title):
244
+ """Clean section title from HTML entities and comments"""
245
+ # Remove HTML comments
246
+ import re
247
+ title = re.sub(r'<!--.*?-->', '', title)
248
+
249
+ # Replace HTML entities
250
+ import html
251
+ title = html.unescape(title)
252
+
253
+ # Remove extra whitespace
254
+ title = ' '.join(title.split())
255
+
256
+ return title.strip()
257
+
258
  # Add this function to update UI with sections from Wikipedia content
259
  def update_ui_with_sections(sections):
260
  """
 
275
  section_title = list(sections.keys())[i]
276
  section_content = sections[section_title]
277
 
278
+ # Clean the section title for display
279
+ clean_title = clean_section_title(section_title)
280
+
281
  # Make section textbox visible with content and label
282
  results.extend([
283
+ gr.update(visible=True, value=section_content, label=f"Section: {clean_title}"),
284
  gr.update(visible=True), # Translate button
285
+ gr.update(visible=True, value="", label=f"Translation: {clean_title}"), # Translation output
286
  gr.update(visible=False) # Debug button (hidden by default)
287
  ])
288
  else: