Update app.py
Browse files
app.py
CHANGED
|
@@ -108,15 +108,22 @@ def fetch_amazon_suggestions(query, market_id="ATVPDKIKX0DER", alias="aps"):
|
|
| 108 |
else:
|
| 109 |
return []
|
| 110 |
|
| 111 |
-
#
|
|
|
|
|
|
|
|
|
|
| 112 |
def expand_keyword(keyword):
|
| 113 |
expanded_keywords = [keyword]
|
| 114 |
for letter in 'abcdefghijklmnopqrstuvwxyz*_':
|
| 115 |
expanded_keywords.append(keyword + " " + letter)
|
| 116 |
expanded_keywords.append(letter + " " + keyword)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
return expanded_keywords
|
| 118 |
|
| 119 |
-
# Función principal
|
| 120 |
def main(keyword):
|
| 121 |
expanded_keywords = expand_keyword(keyword)
|
| 122 |
all_suggestions = {}
|
|
@@ -176,12 +183,12 @@ def main(keyword):
|
|
| 176 |
else:
|
| 177 |
all_suggestions[suggestion] = 1
|
| 178 |
|
| 179 |
-
# Filtrar las top
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
|
| 186 |
# Ordenar y filtrar las sugerencias más frecuentes combinadas
|
| 187 |
sorted_suggestions = sorted(all_suggestions.items(), key=lambda item: item[1], reverse=True)
|
|
@@ -194,54 +201,53 @@ def main(keyword):
|
|
| 194 |
all_suggestions_str += f"<li>{suggestion} - {freq} repeticiones</li>"
|
| 195 |
all_suggestions_str += "</ul>"
|
| 196 |
|
| 197 |
-
# Crear el HTML de salida con un botón de copia
|
| 198 |
html_output = f"""
|
| 199 |
<div>
|
| 200 |
<b>Sugerencias combinadas de Google, DuckDuckGo, YouTube, Bing y Amazon (Top 10 combinadas):</b> <span id='suggestions_text'>{suggestions_str}</span>
|
| 201 |
<button class="lg secondary svelte-cmf5ev" style="font-size: small; padding: 2px; color: #808080ba; border: none; margin-left: 5px;"
|
| 202 |
onclick='navigator.clipboard.writeText(document.getElementById("suggestions_text").innerText).then(() => alert("Texto copiado al portapapeles"))'> ✂ </button>
|
| 203 |
</div>
|
| 204 |
-
|
| 205 |
-
<h4>Top 10 Sugerencias de Google:</h4>
|
| 206 |
<ul>
|
| 207 |
"""
|
| 208 |
-
for suggestion in
|
| 209 |
freq = all_suggestions[suggestion]
|
| 210 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 211 |
html_output += "</ul>"
|
| 212 |
|
| 213 |
html_output += """
|
| 214 |
-
<h4>Top
|
| 215 |
<ul>
|
| 216 |
"""
|
| 217 |
-
for suggestion in
|
| 218 |
freq = all_suggestions[suggestion]
|
| 219 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 220 |
html_output += "</ul>"
|
| 221 |
|
| 222 |
html_output += """
|
| 223 |
-
<h4>Top
|
| 224 |
<ul>
|
| 225 |
"""
|
| 226 |
-
for suggestion in
|
| 227 |
freq = all_suggestions[suggestion]
|
| 228 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 229 |
html_output += "</ul>"
|
| 230 |
|
| 231 |
html_output += """
|
| 232 |
-
<h4>Top
|
| 233 |
<ul>
|
| 234 |
"""
|
| 235 |
-
for suggestion in
|
| 236 |
freq = all_suggestions[suggestion]
|
| 237 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 238 |
html_output += "</ul>"
|
| 239 |
|
| 240 |
html_output += """
|
| 241 |
-
<h4>Top
|
| 242 |
<ul>
|
| 243 |
"""
|
| 244 |
-
for suggestion in
|
| 245 |
freq = all_suggestions[suggestion]
|
| 246 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 247 |
html_output += "</ul>"
|
|
@@ -260,8 +266,8 @@ iface = gr.Interface(
|
|
| 260 |
inputs="text",
|
| 261 |
outputs="html",
|
| 262 |
title="<div style='margin:0 auto;text-align:center'><div style='margin:0 auto;text-align:center'><img style='width:100px;display: inline-table;margin-bottom:-10px' src='https://artxeweb.com/media/files/search.jpg'><p>Sugerencias Combinadas de Google, DuckDuckGo, YouTube, Bing y Amazon</p></div>",
|
| 263 |
-
description="<p style='margin-bottom:10px;text-align:center;background: #ffffff; padding: 8px; border-radius: 8px; border-width: 1px; border: solid 1px #e5e7eb;'>Ingrese una palabra clave para obtener sugerencias de búsqueda relacionadas de Google, DuckDuckGo, YouTube, Bing y Amazon. Se mostrarán las
|
| 264 |
article="<div style='margin-top:10px'><p style='text-align: center !important; background: #ffffff; padding: 5px 30px; border-radius: 8px; border-width: 1px; border: solid 1px #e5e7eb; width: fit-content; margin: auto;'>Desarrollada por <a style='text-decoration: none !important; color: #e12a31 !important;' href='https://artxeweb.com'>© Artxe Web</a></p></div>"
|
| 265 |
)
|
| 266 |
|
| 267 |
-
iface.launch()
|
|
|
|
| 108 |
else:
|
| 109 |
return []
|
| 110 |
|
| 111 |
+
# Lista de stopwords, artículos y conjunciones comunes en español
|
| 112 |
+
stopwords = ["el", "la", "los", "las", "un", "una", "unos", "unas", "y", "o", "de", "que", "por", "para", "con", "sin", "a", "en", "vs", "review", "opiniones" , "opinion" , "caracteristicas"]
|
| 113 |
+
|
| 114 |
+
# Función para expandir la palabra clave añadiendo stopwords, artículos y conjunciones
|
| 115 |
def expand_keyword(keyword):
|
| 116 |
expanded_keywords = [keyword]
|
| 117 |
for letter in 'abcdefghijklmnopqrstuvwxyz*_':
|
| 118 |
expanded_keywords.append(keyword + " " + letter)
|
| 119 |
expanded_keywords.append(letter + " " + keyword)
|
| 120 |
+
# Añadir combinaciones con stopwords, artículos y conjunciones
|
| 121 |
+
for stopword in stopwords:
|
| 122 |
+
expanded_keywords.append(f"{stopword} {keyword}")
|
| 123 |
+
expanded_keywords.append(f"{keyword} {stopword}")
|
| 124 |
return expanded_keywords
|
| 125 |
|
| 126 |
+
# Función principal actualizada
|
| 127 |
def main(keyword):
|
| 128 |
expanded_keywords = expand_keyword(keyword)
|
| 129 |
all_suggestions = {}
|
|
|
|
| 183 |
else:
|
| 184 |
all_suggestions[suggestion] = 1
|
| 185 |
|
| 186 |
+
# Filtrar las top 3 de cada plataforma con su número de repeticiones
|
| 187 |
+
google_top_3 = list(set(google_suggestions_all))[:3]
|
| 188 |
+
duckduckgo_top_3 = list(set(duckduckgo_suggestions_all))[:3]
|
| 189 |
+
youtube_top_3 = list(set(youtube_suggestions_all))[:3]
|
| 190 |
+
bing_top_3 = list(set(bing_suggestions_all))[:3]
|
| 191 |
+
amazon_top_3 = list(set(amazon_suggestions_all))[:3]
|
| 192 |
|
| 193 |
# Ordenar y filtrar las sugerencias más frecuentes combinadas
|
| 194 |
sorted_suggestions = sorted(all_suggestions.items(), key=lambda item: item[1], reverse=True)
|
|
|
|
| 201 |
all_suggestions_str += f"<li>{suggestion} - {freq} repeticiones</li>"
|
| 202 |
all_suggestions_str += "</ul>"
|
| 203 |
|
| 204 |
+
# Crear el HTML de salida con un botón de copia, pero mostrando solo el Top 3
|
| 205 |
html_output = f"""
|
| 206 |
<div>
|
| 207 |
<b>Sugerencias combinadas de Google, DuckDuckGo, YouTube, Bing y Amazon (Top 10 combinadas):</b> <span id='suggestions_text'>{suggestions_str}</span>
|
| 208 |
<button class="lg secondary svelte-cmf5ev" style="font-size: small; padding: 2px; color: #808080ba; border: none; margin-left: 5px;"
|
| 209 |
onclick='navigator.clipboard.writeText(document.getElementById("suggestions_text").innerText).then(() => alert("Texto copiado al portapapeles"))'> ✂ </button>
|
| 210 |
</div>
|
| 211 |
+
<h4>Top 3 Sugerencias de Google:</h4>
|
|
|
|
| 212 |
<ul>
|
| 213 |
"""
|
| 214 |
+
for suggestion in google_top_3:
|
| 215 |
freq = all_suggestions[suggestion]
|
| 216 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 217 |
html_output += "</ul>"
|
| 218 |
|
| 219 |
html_output += """
|
| 220 |
+
<h4>Top 3 Sugerencias de DuckDuckGo:</h4>
|
| 221 |
<ul>
|
| 222 |
"""
|
| 223 |
+
for suggestion in duckduckgo_top_3:
|
| 224 |
freq = all_suggestions[suggestion]
|
| 225 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 226 |
html_output += "</ul>"
|
| 227 |
|
| 228 |
html_output += """
|
| 229 |
+
<h4>Top 3 Sugerencias de YouTube:</h4>
|
| 230 |
<ul>
|
| 231 |
"""
|
| 232 |
+
for suggestion in youtube_top_3:
|
| 233 |
freq = all_suggestions[suggestion]
|
| 234 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 235 |
html_output += "</ul>"
|
| 236 |
|
| 237 |
html_output += """
|
| 238 |
+
<h4>Top 3 Sugerencias de Bing:</h4>
|
| 239 |
<ul>
|
| 240 |
"""
|
| 241 |
+
for suggestion in bing_top_3:
|
| 242 |
freq = all_suggestions[suggestion]
|
| 243 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 244 |
html_output += "</ul>"
|
| 245 |
|
| 246 |
html_output += """
|
| 247 |
+
<h4>Top 3 Sugerencias de Amazon:</h4>
|
| 248 |
<ul>
|
| 249 |
"""
|
| 250 |
+
for suggestion in amazon_top_3:
|
| 251 |
freq = all_suggestions[suggestion]
|
| 252 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 253 |
html_output += "</ul>"
|
|
|
|
| 266 |
inputs="text",
|
| 267 |
outputs="html",
|
| 268 |
title="<div style='margin:0 auto;text-align:center'><div style='margin:0 auto;text-align:center'><img style='width:100px;display: inline-table;margin-bottom:-10px' src='https://artxeweb.com/media/files/search.jpg'><p>Sugerencias Combinadas de Google, DuckDuckGo, YouTube, Bing y Amazon</p></div>",
|
| 269 |
+
description="<p style='margin-bottom:10px;text-align:center;background: #ffffff; padding: 8px; border-radius: 8px; border-width: 1px; border: solid 1px #e5e7eb;'>Ingrese una palabra clave para obtener sugerencias de búsqueda relacionadas de Google, DuckDuckGo, YouTube, Bing y Amazon. Se mostrarán las 3 primeras sugerencias combinadas y también las 3 principales de cada plataforma por separado.</p>",
|
| 270 |
article="<div style='margin-top:10px'><p style='text-align: center !important; background: #ffffff; padding: 5px 30px; border-radius: 8px; border-width: 1px; border: solid 1px #e5e7eb; width: fit-content; margin: auto;'>Desarrollada por <a style='text-decoration: none !important; color: #e12a31 !important;' href='https://artxeweb.com'>© Artxe Web</a></p></div>"
|
| 271 |
)
|
| 272 |
|
| 273 |
+
iface.launch()
|