Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import urllib.parse
|
|
|
|
| 4 |
|
| 5 |
# Función para obtener sugerencias de DuckDuckGo
|
| 6 |
def fetch_duckduckgo_suggestions(query, lang_code="es"):
|
|
@@ -55,25 +56,6 @@ def fetch_youtube_suggestions(query, lang_code="es"):
|
|
| 55 |
else:
|
| 56 |
return []
|
| 57 |
|
| 58 |
-
# Función para obtener solo las sugerencias correctas de Yahoo
|
| 59 |
-
def fetch_yahoo_suggestion(query):
|
| 60 |
-
encoded_query = urllib.parse.quote(query)
|
| 61 |
-
url = f"https://search.yahoo.com/sugg/gossip/gossip-us-ura/?output=sd1&command={encoded_query}"
|
| 62 |
-
response = requests.get(url)
|
| 63 |
-
if response.status_code == 200:
|
| 64 |
-
try:
|
| 65 |
-
data = response.json()
|
| 66 |
-
# Solo tomamos las sugerencias bajo la clave 'r' y retornamos
|
| 67 |
-
if 'r' in data:
|
| 68 |
-
return [item['k'] for item in data['r']] # Devolvemos todas las sugerencias bajo 'r'
|
| 69 |
-
else:
|
| 70 |
-
return []
|
| 71 |
-
except ValueError:
|
| 72 |
-
print("Error decodificando JSON de Yahoo")
|
| 73 |
-
return []
|
| 74 |
-
else:
|
| 75 |
-
return []
|
| 76 |
-
|
| 77 |
# Función para expandir la palabra clave
|
| 78 |
def expand_keyword(keyword):
|
| 79 |
expanded_keywords = [keyword]
|
|
@@ -89,7 +71,6 @@ def main(keyword):
|
|
| 89 |
google_suggestions_all = []
|
| 90 |
duckduckgo_suggestions_all = []
|
| 91 |
youtube_suggestions_all = []
|
| 92 |
-
yahoo_suggestions_all = []
|
| 93 |
|
| 94 |
# Obtener sugerencias de DuckDuckGo
|
| 95 |
for exp_keyword in expanded_keywords:
|
|
@@ -121,21 +102,10 @@ def main(keyword):
|
|
| 121 |
else:
|
| 122 |
all_suggestions[suggestion] = 1
|
| 123 |
|
| 124 |
-
# Obtener solo las sugerencias correctas de Yahoo
|
| 125 |
-
for exp_keyword in expanded_keywords:
|
| 126 |
-
suggestions = fetch_yahoo_suggestion(exp_keyword)
|
| 127 |
-
yahoo_suggestions_all.extend(suggestions)
|
| 128 |
-
for suggestion in suggestions:
|
| 129 |
-
if suggestion in all_suggestions:
|
| 130 |
-
all_suggestions[suggestion] += 1
|
| 131 |
-
else:
|
| 132 |
-
all_suggestions[suggestion] = 1
|
| 133 |
-
|
| 134 |
# Filtrar las top 10 de cada plataforma
|
| 135 |
google_top_10 = list(set(google_suggestions_all))[:10]
|
| 136 |
duckduckgo_top_10 = list(set(duckduckgo_suggestions_all))[:10]
|
| 137 |
youtube_top_10 = list(set(youtube_suggestions_all))[:10]
|
| 138 |
-
yahoo_top_10 = list(set(yahoo_suggestions_all))[:10]
|
| 139 |
|
| 140 |
# Ordenar y filtrar las sugerencias más frecuentes combinadas
|
| 141 |
sorted_suggestions = sorted(all_suggestions.items(), key=lambda item: item[1], reverse=True)
|
|
@@ -145,7 +115,7 @@ def main(keyword):
|
|
| 145 |
# Crear el HTML de salida con un botón de copia
|
| 146 |
html_output = f"""
|
| 147 |
<div>
|
| 148 |
-
<b>Sugerencias combinadas de Google, DuckDuckGo
|
| 149 |
<button class="lg secondary svelte-cmf5ev" style="font-size: small; padding: 2px; color: #808080ba; border: none; margin-left: 5px;"
|
| 150 |
onclick='navigator.clipboard.writeText(document.getElementById("suggestions_text").innerText).then(() => alert("Texto copiado al portapapeles"))'> ✂ </button>
|
| 151 |
</div>
|
|
@@ -173,14 +143,6 @@ def main(keyword):
|
|
| 173 |
html_output += f"<li>{suggestion}</li>"
|
| 174 |
html_output += "</ul>"
|
| 175 |
|
| 176 |
-
html_output += """
|
| 177 |
-
<h4>Top 10 Sugerencias de Yahoo:</h4>
|
| 178 |
-
<ul>
|
| 179 |
-
"""
|
| 180 |
-
for suggestion in yahoo_top_10:
|
| 181 |
-
html_output += f"<li>{suggestion}</li>"
|
| 182 |
-
html_output += "</ul>"
|
| 183 |
-
|
| 184 |
return html_output
|
| 185 |
|
| 186 |
# Interfaz de Gradio
|
|
@@ -188,8 +150,8 @@ iface = gr.Interface(
|
|
| 188 |
fn=main,
|
| 189 |
inputs="text",
|
| 190 |
outputs="html",
|
| 191 |
-
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
|
| 192 |
-
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
|
| 193 |
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>"
|
| 194 |
)
|
| 195 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import urllib.parse
|
| 4 |
+
import re
|
| 5 |
|
| 6 |
# Función para obtener sugerencias de DuckDuckGo
|
| 7 |
def fetch_duckduckgo_suggestions(query, lang_code="es"):
|
|
|
|
| 56 |
else:
|
| 57 |
return []
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# Función para expandir la palabra clave
|
| 60 |
def expand_keyword(keyword):
|
| 61 |
expanded_keywords = [keyword]
|
|
|
|
| 71 |
google_suggestions_all = []
|
| 72 |
duckduckgo_suggestions_all = []
|
| 73 |
youtube_suggestions_all = []
|
|
|
|
| 74 |
|
| 75 |
# Obtener sugerencias de DuckDuckGo
|
| 76 |
for exp_keyword in expanded_keywords:
|
|
|
|
| 102 |
else:
|
| 103 |
all_suggestions[suggestion] = 1
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
# Filtrar las top 10 de cada plataforma
|
| 106 |
google_top_10 = list(set(google_suggestions_all))[:10]
|
| 107 |
duckduckgo_top_10 = list(set(duckduckgo_suggestions_all))[:10]
|
| 108 |
youtube_top_10 = list(set(youtube_suggestions_all))[:10]
|
|
|
|
| 109 |
|
| 110 |
# Ordenar y filtrar las sugerencias más frecuentes combinadas
|
| 111 |
sorted_suggestions = sorted(all_suggestions.items(), key=lambda item: item[1], reverse=True)
|
|
|
|
| 115 |
# Crear el HTML de salida con un botón de copia
|
| 116 |
html_output = f"""
|
| 117 |
<div>
|
| 118 |
+
<b>Sugerencias combinadas de Google, DuckDuckGo y YouTube (Top 10 combinadas):</b> <span id='suggestions_text'>{suggestions_str}</span>
|
| 119 |
<button class="lg secondary svelte-cmf5ev" style="font-size: small; padding: 2px; color: #808080ba; border: none; margin-left: 5px;"
|
| 120 |
onclick='navigator.clipboard.writeText(document.getElementById("suggestions_text").innerText).then(() => alert("Texto copiado al portapapeles"))'> ✂ </button>
|
| 121 |
</div>
|
|
|
|
| 143 |
html_output += f"<li>{suggestion}</li>"
|
| 144 |
html_output += "</ul>"
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
return html_output
|
| 147 |
|
| 148 |
# Interfaz de Gradio
|
|
|
|
| 150 |
fn=main,
|
| 151 |
inputs="text",
|
| 152 |
outputs="html",
|
| 153 |
+
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 y YouTube</p></div>",
|
| 154 |
+
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 y YouTube. Se mostrarán las 10 primeras sugerencias combinadas y también las 10 principales de cada plataforma por separado.</p>",
|
| 155 |
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>"
|
| 156 |
)
|
| 157 |
|