Update app.py
Browse files
app.py
CHANGED
|
@@ -94,15 +94,23 @@ def fetch_amazon_suggestions(query, market_id="ATVPDKIKX0DER", alias="aps"):
|
|
| 94 |
else:
|
| 95 |
return []
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
# Función para contar y obtener las top N sugerencias más repetidas
|
| 98 |
-
def get_top_suggestions(suggestions, top_n=
|
| 99 |
suggestion_counter = Counter(suggestions)
|
| 100 |
return suggestion_counter.most_common(top_n)
|
| 101 |
|
| 102 |
-
# Función principal
|
| 103 |
def main(keyword):
|
| 104 |
expanded_keywords = expand_keyword(keyword)
|
| 105 |
-
all_suggestions =
|
| 106 |
google_suggestions_all = []
|
| 107 |
duckduckgo_suggestions_all = []
|
| 108 |
youtube_suggestions_all = []
|
|
@@ -113,54 +121,77 @@ def main(keyword):
|
|
| 113 |
for exp_keyword in expanded_keywords:
|
| 114 |
suggestions = fetch_duckduckgo_suggestions(exp_keyword)
|
| 115 |
duckduckgo_suggestions_all.extend(suggestions)
|
| 116 |
-
|
|
|
|
| 117 |
|
| 118 |
# Obtener sugerencias de Google
|
| 119 |
for exp_keyword in expanded_keywords:
|
| 120 |
suggestions = fetch_google_suggestions(exp_keyword)
|
| 121 |
google_suggestions_all.extend(suggestions)
|
| 122 |
-
|
|
|
|
| 123 |
|
| 124 |
# Obtener sugerencias de YouTube
|
| 125 |
for exp_keyword in expanded_keywords:
|
| 126 |
suggestions = fetch_youtube_suggestions(exp_keyword)
|
| 127 |
youtube_suggestions_all.extend(suggestions)
|
| 128 |
-
|
|
|
|
| 129 |
|
| 130 |
# Obtener sugerencias de Bing
|
| 131 |
for exp_keyword in expanded_keywords:
|
| 132 |
suggestions = fetch_bing_suggestions(exp_keyword)
|
| 133 |
bing_suggestions_all.extend(suggestions)
|
| 134 |
-
|
|
|
|
| 135 |
|
| 136 |
# Obtener sugerencias de Amazon
|
| 137 |
for exp_keyword in expanded_keywords:
|
| 138 |
suggestions = fetch_amazon_suggestions(exp_keyword)
|
| 139 |
amazon_suggestions_all.extend(suggestions)
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 153 |
-
html_output += "</ul><h4>Top
|
| 154 |
-
for suggestion, freq in
|
| 155 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 156 |
-
html_output += "</ul><h4>Top
|
| 157 |
-
for suggestion, freq in
|
| 158 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 159 |
-
html_output += "</ul><h4>Top
|
| 160 |
-
for suggestion, freq in
|
| 161 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 162 |
-
html_output += "</ul><h4>Top
|
| 163 |
-
for suggestion, freq in
|
| 164 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 165 |
html_output += "</ul>"
|
| 166 |
|
|
@@ -171,9 +202,9 @@ iface = gr.Interface(
|
|
| 171 |
fn=main,
|
| 172 |
inputs="text",
|
| 173 |
outputs="html",
|
| 174 |
-
title="Sugerencias Combinadas de Google, DuckDuckGo, YouTube, Bing y Amazon",
|
| 175 |
-
description="Ingrese una palabra clave para obtener sugerencias de búsqueda relacionadas.",
|
| 176 |
-
article="<p>Desarrollada por
|
| 177 |
)
|
| 178 |
|
| 179 |
iface.launch()
|
|
|
|
| 94 |
else:
|
| 95 |
return []
|
| 96 |
|
| 97 |
+
# Función para expandir la palabra clave
|
| 98 |
+
def expand_keyword(keyword):
|
| 99 |
+
expanded_keywords = [keyword]
|
| 100 |
+
for letter in 'abcdefghijklmnopqrstuvwxyz*_':
|
| 101 |
+
expanded_keywords.append(keyword + " " + letter)
|
| 102 |
+
expanded_keywords.append(letter + " " + keyword)
|
| 103 |
+
return expanded_keywords
|
| 104 |
+
|
| 105 |
# Función para contar y obtener las top N sugerencias más repetidas
|
| 106 |
+
def get_top_suggestions(suggestions, top_n=10):
|
| 107 |
suggestion_counter = Counter(suggestions)
|
| 108 |
return suggestion_counter.most_common(top_n)
|
| 109 |
|
| 110 |
+
# Función principal
|
| 111 |
def main(keyword):
|
| 112 |
expanded_keywords = expand_keyword(keyword)
|
| 113 |
+
all_suggestions = {}
|
| 114 |
google_suggestions_all = []
|
| 115 |
duckduckgo_suggestions_all = []
|
| 116 |
youtube_suggestions_all = []
|
|
|
|
| 121 |
for exp_keyword in expanded_keywords:
|
| 122 |
suggestions = fetch_duckduckgo_suggestions(exp_keyword)
|
| 123 |
duckduckgo_suggestions_all.extend(suggestions)
|
| 124 |
+
for suggestion in suggestions:
|
| 125 |
+
all_suggestions[suggestion] = all_suggestions.get(suggestion, 0) + 1
|
| 126 |
|
| 127 |
# Obtener sugerencias de Google
|
| 128 |
for exp_keyword in expanded_keywords:
|
| 129 |
suggestions = fetch_google_suggestions(exp_keyword)
|
| 130 |
google_suggestions_all.extend(suggestions)
|
| 131 |
+
for suggestion in suggestions:
|
| 132 |
+
all_suggestions[suggestion] = all_suggestions.get(suggestion, 0) + 1
|
| 133 |
|
| 134 |
# Obtener sugerencias de YouTube
|
| 135 |
for exp_keyword in expanded_keywords:
|
| 136 |
suggestions = fetch_youtube_suggestions(exp_keyword)
|
| 137 |
youtube_suggestions_all.extend(suggestions)
|
| 138 |
+
for suggestion in suggestions:
|
| 139 |
+
all_suggestions[suggestion] = all_suggestions.get(suggestion, 0) + 1
|
| 140 |
|
| 141 |
# Obtener sugerencias de Bing
|
| 142 |
for exp_keyword in expanded_keywords:
|
| 143 |
suggestions = fetch_bing_suggestions(exp_keyword)
|
| 144 |
bing_suggestions_all.extend(suggestions)
|
| 145 |
+
for suggestion in suggestions:
|
| 146 |
+
all_suggestions[suggestion] = all_suggestions.get(suggestion, 0) + 1
|
| 147 |
|
| 148 |
# Obtener sugerencias de Amazon
|
| 149 |
for exp_keyword in expanded_keywords:
|
| 150 |
suggestions = fetch_amazon_suggestions(exp_keyword)
|
| 151 |
amazon_suggestions_all.extend(suggestions)
|
| 152 |
+
for suggestion in suggestions:
|
| 153 |
+
all_suggestions[suggestion] = all_suggestions.get(suggestion, 0) + 1
|
| 154 |
+
|
| 155 |
+
# Obtener las top 10 sugerencias de cada plataforma
|
| 156 |
+
google_top_10 = get_top_suggestions(google_suggestions_all, top_n=10)
|
| 157 |
+
duckduckgo_top_10 = get_top_suggestions(duckduckgo_suggestions_all, top_n=10)
|
| 158 |
+
youtube_top_10 = get_top_suggestions(youtube_suggestions_all, top_n=10)
|
| 159 |
+
bing_top_10 = get_top_suggestions(bing_suggestions_all, top_n=10)
|
| 160 |
+
amazon_top_10 = get_top_suggestions(amazon_suggestions_all, top_n=10)
|
| 161 |
+
|
| 162 |
+
# Ordenar las sugerencias combinadas por frecuencia
|
| 163 |
+
combined_top_10_suggestions = get_top_suggestions(all_suggestions, top_n=10)
|
| 164 |
+
suggestions_str = ", ".join([f"{sug} ({freq})" for sug, freq in combined_top_10_suggestions])
|
| 165 |
+
|
| 166 |
+
# Crear la lista de todas las palabras clave con su número de repeticiones
|
| 167 |
+
all_suggestions_str = "<ul>"
|
| 168 |
+
for suggestion, freq in combined_top_10_suggestions:
|
| 169 |
+
all_suggestions_str += f"<li>{suggestion} - {freq} repeticiones</li>"
|
| 170 |
+
all_suggestions_str += "</ul>"
|
| 171 |
+
|
| 172 |
+
# Crear el HTML de salida con un botón de copia
|
| 173 |
+
html_output = f"""
|
| 174 |
+
<div>
|
| 175 |
+
<b>Sugerencias combinadas de Google, DuckDuckGo, YouTube, Bing y Amazon (Top 10 combinadas):</b> <span id='suggestions_text'>{suggestions_str}</span>
|
| 176 |
+
<button class="lg secondary svelte-cmf5ev" style="font-size: small; padding: 2px; color: #808080ba; border: none; margin-left: 5px;"
|
| 177 |
+
onclick='navigator.clipboard.writeText(document.getElementById("suggestions_text").innerText).then(() => alert("Texto copiado al portapapeles"))'> ✂ </button>
|
| 178 |
+
</div>
|
| 179 |
+
|
| 180 |
+
<h4>Top 10 Sugerencias de Google:</h4><ul>
|
| 181 |
+
"""
|
| 182 |
+
for suggestion, freq in google_top_10:
|
| 183 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 184 |
+
html_output += "</ul><h4>Top 10 Sugerencias de DuckDuckGo:</h4><ul>"
|
| 185 |
+
for suggestion, freq in duckduckgo_top_10:
|
| 186 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 187 |
+
html_output += "</ul><h4>Top 10 Sugerencias de YouTube:</h4><ul>"
|
| 188 |
+
for suggestion, freq in youtube_top_10:
|
| 189 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 190 |
+
html_output += "</ul><h4>Top 10 Sugerencias de Bing:</h4><ul>"
|
| 191 |
+
for suggestion, freq in bing_top_10:
|
| 192 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 193 |
+
html_output += "</ul><h4>Top 10 Sugerencias de Amazon:</h4><ul>"
|
| 194 |
+
for suggestion, freq in amazon_top_10:
|
| 195 |
html_output += f"<li>{suggestion} ({freq})</li>"
|
| 196 |
html_output += "</ul>"
|
| 197 |
|
|
|
|
| 202 |
fn=main,
|
| 203 |
inputs="text",
|
| 204 |
outputs="html",
|
| 205 |
+
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>",
|
| 206 |
+
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 10 primeras sugerencias combinadas y también las 10 principales de cada plataforma por separado.</p>",
|
| 207 |
+
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>"
|
| 208 |
)
|
| 209 |
|
| 210 |
iface.launch()
|