Update app.py
Browse files
app.py
CHANGED
|
@@ -58,7 +58,7 @@ def fetch_youtube_suggestions(query, lang_code="es"):
|
|
| 58 |
return []
|
| 59 |
|
| 60 |
# Función para obtener sugerencias de Bing
|
| 61 |
-
def fetch_bing_suggestions(query, market="
|
| 62 |
url = "https://api.bing.com/qsml.aspx"
|
| 63 |
params = {
|
| 64 |
"Market": market,
|
|
@@ -87,6 +87,27 @@ def fetch_bing_suggestions(query, market="en-US"):
|
|
| 87 |
else:
|
| 88 |
return []
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
# Función para expandir la palabra clave
|
| 91 |
def expand_keyword(keyword):
|
| 92 |
expanded_keywords = [keyword]
|
|
@@ -103,6 +124,7 @@ def main(keyword):
|
|
| 103 |
duckduckgo_suggestions_all = []
|
| 104 |
youtube_suggestions_all = []
|
| 105 |
bing_suggestions_all = []
|
|
|
|
| 106 |
|
| 107 |
# Obtener sugerencias de DuckDuckGo
|
| 108 |
for exp_keyword in expanded_keywords:
|
|
@@ -144,11 +166,22 @@ def main(keyword):
|
|
| 144 |
else:
|
| 145 |
all_suggestions[suggestion] = 1
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
# Filtrar las top 10 de cada plataforma
|
| 148 |
google_top_10 = list(set(google_suggestions_all))[:10]
|
| 149 |
duckduckgo_top_10 = list(set(duckduckgo_suggestions_all))[:10]
|
| 150 |
youtube_top_10 = list(set(youtube_suggestions_all))[:10]
|
| 151 |
bing_top_10 = list(set(bing_suggestions_all))[:10]
|
|
|
|
| 152 |
|
| 153 |
# Ordenar y filtrar las sugerencias más frecuentes combinadas
|
| 154 |
sorted_suggestions = sorted(all_suggestions.items(), key=lambda item: item[1], reverse=True)
|
|
@@ -158,7 +191,7 @@ def main(keyword):
|
|
| 158 |
# Crear el HTML de salida con un botón de copia
|
| 159 |
html_output = f"""
|
| 160 |
<div>
|
| 161 |
-
<b>Sugerencias combinadas de Google, DuckDuckGo, YouTube y
|
| 162 |
<button class="lg secondary svelte-cmf5ev" style="font-size: small; padding: 2px; color: #808080ba; border: none; margin-left: 5px;"
|
| 163 |
onclick='navigator.clipboard.writeText(document.getElementById("suggestions_text").innerText).then(() => alert("Texto copiado al portapapeles"))'> ✂ </button>
|
| 164 |
</div>
|
|
@@ -194,6 +227,14 @@ def main(keyword):
|
|
| 194 |
html_output += f"<li>{suggestion}</li>"
|
| 195 |
html_output += "</ul>"
|
| 196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
return html_output
|
| 198 |
|
| 199 |
# Interfaz de Gradio
|
|
@@ -201,8 +242,8 @@ iface = gr.Interface(
|
|
| 201 |
fn=main,
|
| 202 |
inputs="text",
|
| 203 |
outputs="html",
|
| 204 |
-
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 y
|
| 205 |
-
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 y
|
| 206 |
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>"
|
| 207 |
)
|
| 208 |
|
|
|
|
| 58 |
return []
|
| 59 |
|
| 60 |
# Función para obtener sugerencias de Bing
|
| 61 |
+
def fetch_bing_suggestions(query, market="es-ES"):
|
| 62 |
url = "https://api.bing.com/qsml.aspx"
|
| 63 |
params = {
|
| 64 |
"Market": market,
|
|
|
|
| 87 |
else:
|
| 88 |
return []
|
| 89 |
|
| 90 |
+
# Función para obtener sugerencias de Amazon
|
| 91 |
+
def fetch_amazon_suggestions(query, market_id="ATVPDKIKX0DER", alias="aps"):
|
| 92 |
+
url = "https://completion.amazon.com/api/2017/suggestions"
|
| 93 |
+
params = {
|
| 94 |
+
"mid": market_id,
|
| 95 |
+
"alias": alias,
|
| 96 |
+
"prefix": query
|
| 97 |
+
}
|
| 98 |
+
response = requests.get(url, params=params)
|
| 99 |
+
|
| 100 |
+
if response.status_code == 200:
|
| 101 |
+
try:
|
| 102 |
+
data = response.json()
|
| 103 |
+
# Extraemos las sugerencias desde el JSON bajo la clave 'suggestions'
|
| 104 |
+
return [item['value'] for item in data.get('suggestions', [])]
|
| 105 |
+
except ValueError:
|
| 106 |
+
print("Error decodificando JSON de Amazon")
|
| 107 |
+
return []
|
| 108 |
+
else:
|
| 109 |
+
return []
|
| 110 |
+
|
| 111 |
# Función para expandir la palabra clave
|
| 112 |
def expand_keyword(keyword):
|
| 113 |
expanded_keywords = [keyword]
|
|
|
|
| 124 |
duckduckgo_suggestions_all = []
|
| 125 |
youtube_suggestions_all = []
|
| 126 |
bing_suggestions_all = []
|
| 127 |
+
amazon_suggestions_all = []
|
| 128 |
|
| 129 |
# Obtener sugerencias de DuckDuckGo
|
| 130 |
for exp_keyword in expanded_keywords:
|
|
|
|
| 166 |
else:
|
| 167 |
all_suggestions[suggestion] = 1
|
| 168 |
|
| 169 |
+
# Obtener sugerencias de Amazon
|
| 170 |
+
for exp_keyword in expanded_keywords:
|
| 171 |
+
suggestions = fetch_amazon_suggestions(exp_keyword)
|
| 172 |
+
amazon_suggestions_all.extend(suggestions)
|
| 173 |
+
for suggestion in suggestions:
|
| 174 |
+
if suggestion in all_suggestions:
|
| 175 |
+
all_suggestions[suggestion] += 1
|
| 176 |
+
else:
|
| 177 |
+
all_suggestions[suggestion] = 1
|
| 178 |
+
|
| 179 |
# Filtrar las top 10 de cada plataforma
|
| 180 |
google_top_10 = list(set(google_suggestions_all))[:10]
|
| 181 |
duckduckgo_top_10 = list(set(duckduckgo_suggestions_all))[:10]
|
| 182 |
youtube_top_10 = list(set(youtube_suggestions_all))[:10]
|
| 183 |
bing_top_10 = list(set(bing_suggestions_all))[:10]
|
| 184 |
+
amazon_top_10 = list(set(amazon_suggestions_all))[:10]
|
| 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)
|
|
|
|
| 191 |
# Crear el HTML de salida con un botón de copia
|
| 192 |
html_output = f"""
|
| 193 |
<div>
|
| 194 |
+
<b>Sugerencias combinadas de Google, DuckDuckGo, YouTube, Bing y Amazon (Top 10 combinadas):</b> <span id='suggestions_text'>{suggestions_str}</span>
|
| 195 |
<button class="lg secondary svelte-cmf5ev" style="font-size: small; padding: 2px; color: #808080ba; border: none; margin-left: 5px;"
|
| 196 |
onclick='navigator.clipboard.writeText(document.getElementById("suggestions_text").innerText).then(() => alert("Texto copiado al portapapeles"))'> ✂ </button>
|
| 197 |
</div>
|
|
|
|
| 227 |
html_output += f"<li>{suggestion}</li>"
|
| 228 |
html_output += "</ul>"
|
| 229 |
|
| 230 |
+
html_output += """
|
| 231 |
+
<h4>Top 10 Sugerencias de Amazon:</h4>
|
| 232 |
+
<ul>
|
| 233 |
+
"""
|
| 234 |
+
for suggestion in amazon_top_10:
|
| 235 |
+
html_output += f"<li>{suggestion}</li>"
|
| 236 |
+
html_output += "</ul>"
|
| 237 |
+
|
| 238 |
return html_output
|
| 239 |
|
| 240 |
# Interfaz de Gradio
|
|
|
|
| 242 |
fn=main,
|
| 243 |
inputs="text",
|
| 244 |
outputs="html",
|
| 245 |
+
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>",
|
| 246 |
+
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>",
|
| 247 |
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>"
|
| 248 |
)
|
| 249 |
|