Update app.py
Browse files
app.py
CHANGED
@@ -59,8 +59,24 @@ class Texte(db.Model):
|
|
59 |
# --- Fonctions utilitaires ---
|
60 |
|
61 |
def sanitize_html(html_content):
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
def generate_content_from_youtube(youtube_url, prompt, model_name):
|
65 |
"""Génère du contenu à partir d'une vidéo YouTube en utilisant l'API Gemini."""
|
66 |
try:
|
|
|
59 |
# --- Fonctions utilitaires ---
|
60 |
|
61 |
def sanitize_html(html_content):
|
62 |
+
"""Assainit le contenu HTML (comme dans ton admin.py)."""
|
63 |
+
allowed_tags = [
|
64 |
+
'a', 'abbr', 'acronym', 'b', 'blockquote', 'br', 'code', 'div', 'em',
|
65 |
+
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'li', 'ol', 'p',
|
66 |
+
'pre', 'span', 'strong', 'table', 'tbody', 'td', 'th', 'thead', 'tr', 'ul'
|
67 |
+
]
|
68 |
+
allowed_attributes = {
|
69 |
+
'*': ['class', 'id', 'style'],
|
70 |
+
'a': ['href', 'rel', 'target', 'title'],
|
71 |
+
'img': ['alt', 'src', 'width', 'height'],
|
72 |
+
'table': ['border', 'cellpadding', 'cellspacing']
|
73 |
+
}
|
74 |
+
cleaned_html = clean(html_content, tags=allowed_tags, attributes=allowed_attributes, strip=True)
|
75 |
+
soup = BeautifulSoup(cleaned_html, 'html.parser')
|
76 |
+
for tag in soup.find_all():
|
77 |
+
if not tag.contents and tag.name not in ['br', 'hr', 'img']:
|
78 |
+
tag.decompose()
|
79 |
+
return str(soup)
|
80 |
def generate_content_from_youtube(youtube_url, prompt, model_name):
|
81 |
"""Génère du contenu à partir d'une vidéo YouTube en utilisant l'API Gemini."""
|
82 |
try:
|