Bentham commited on
Commit
3bcaa2d
·
verified ·
1 Parent(s): c6372cf

readability

Browse files
Files changed (1) hide show
  1. main.py +8 -11
main.py CHANGED
@@ -14,7 +14,7 @@ import json
14
  import asyncio # Added for asynchronous functionality
15
 
16
  from openai import AsyncOpenAI # Import AsyncOpenAI
17
- from newspaper import Article
18
 
19
 
20
  import instructor # Import instructor for patching
@@ -156,19 +156,16 @@ async def convert_to_accessible_html(input_filename, ext, base_filename, image_c
156
  with open(input_filename, 'r', encoding='utf-8') as f:
157
  html_content = f.read()
158
  try:
159
- # Utiliser newspaper3k pour extraire le texte principal
160
- article = Article(url='')
161
- article.set_html(html_content)
162
- article.parse()
163
-
164
- # Obtenir le texte principal
165
- main_text = article.text
166
-
167
  # Reconstruire le HTML avec le texte principal
168
  html_content = f"<html><body><p>{main_text}</p></body></html>"
169
- logging.debug("Contenu HTML nettoyé avec newspaper3k.")
170
  except Exception as e:
171
- logging.error(f"Erreur lors du nettoyage avec newspaper3k : {str(e)}")
172
  # Vous pouvez décider de continuer avec le contenu HTML original ou arrêter le traitement
173
  return None # Ou continuez avec html_content non modifié
174
  # Conversion from PDF to HTML with PyMuPDF
 
14
  import asyncio # Added for asynchronous functionality
15
 
16
  from openai import AsyncOpenAI # Import AsyncOpenAI
17
+ from readability import Document
18
 
19
 
20
  import instructor # Import instructor for patching
 
156
  with open(input_filename, 'r', encoding='utf-8') as f:
157
  html_content = f.read()
158
  try:
159
+ # Utiliser readability-lxml pour extraire le contenu principal
160
+ doc = Document(html_content)
161
+ main_html = doc.summary() # Extrait le HTML principal
162
+ main_text = doc.text() # Extrait le texte principal
163
+
 
 
 
164
  # Reconstruire le HTML avec le texte principal
165
  html_content = f"<html><body><p>{main_text}</p></body></html>"
166
+ logging.debug("Contenu HTML nettoyé avec readability-lxml.")
167
  except Exception as e:
168
+ logging.error(f"Erreur lors du nettoyage avec readability-lxml : {str(e)}")
169
  # Vous pouvez décider de continuer avec le contenu HTML original ou arrêter le traitement
170
  return None # Ou continuez avec html_content non modifié
171
  # Conversion from PDF to HTML with PyMuPDF