tx3bas commited on
Commit
62efa1b
·
verified ·
1 Parent(s): baa51b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -31
app.py CHANGED
@@ -5,7 +5,6 @@ import re
5
  import xmltodict
6
  from collections import Counter
7
  import unicodedata
8
- import pandas as pd # Para manejar CSV
9
 
10
  # Función para normalizar palabras clave (elimina tildes y convierte a minúsculas)
11
  def normalize_keyword(keyword):
@@ -166,7 +165,7 @@ def get_top_suggestions(suggestions, top_n=10):
166
  suggestion_counter = Counter(suggestions)
167
  return suggestion_counter.most_common(top_n)
168
 
169
- # Función principal que ahora también devuelve un archivo CSV
170
  def main(keyword):
171
  expanded_keywords = expand_keyword(keyword)
172
  all_suggestions = {}
@@ -229,47 +228,81 @@ def main(keyword):
229
  for suggestion in suggestions:
230
  all_suggestions[suggestion] = all_suggestions.get(suggestion, 0) + 1
231
 
232
- # Obtener las top 10 sugerencias de cada plataforma
233
- google_top_10 = get_top_suggestions(google_suggestions_all, top_n=10)
234
- duckduckgo_top_10 = get_top_suggestions(duckduckgo_suggestions_all, top_n=10)
235
- youtube_top_10 = get_top_suggestions(youtube_suggestions_all, top_n=10)
236
- bing_top_10 = get_top_suggestions(bing_suggestions_all, top_n=10)
237
- amazon_top_10 = get_top_suggestions(amazon_suggestions_all, top_n=10)
238
- qwant_top_10 = get_top_suggestions(qwant_suggestions_all, top_n=10)
239
- brave_top_10 = get_top_suggestions(brave_suggestions_all, top_n=10)
240
 
241
- # Ordenar las sugerencias combinadas por frecuencia
242
- combined_suggestions = sorted(all_suggestions.items(), key=lambda item: item[1], reverse=True)
 
 
 
 
 
 
243
 
244
- # Crear un DataFrame de Pandas para las sugerencias y relevancias
245
- df = pd.DataFrame(combined_suggestions, columns=["keyword", "relevancia"])
 
 
 
246
 
247
- # Guardar el DataFrame en un archivo CSV
248
- csv_file = "/tmp/keywords_relevancia.csv"
249
- df.to_csv(csv_file, index=False)
250
-
251
- # Crear el HTML de salida con las sugerencias (ya está hecho en tu código anterior)
252
  html_output = f"""
253
  <div>
254
- <b>Sugerencias combinadas de Google, DuckDuckGo, YouTube, Bing, Amazon, Qwant y Brave (Top 10 combinadas):</b>
255
- <span id='suggestions_text'>{', '.join([f'{sug} ({freq})' for sug, freq in combined_suggestions[:10]])}</span>
256
- <button class="lg secondary svelte-cmf5ev" style="font-size: small; padding: 2px; color: #808080ba; border: none; margin-left: 5px;"
257
- onclick='navigator.clipboard.writeText(document.getElementById("suggestions_text").innerText).then(() => alert("Texto copiado al portapapeles"))'>
258
- &nbsp;✂&nbsp;</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  </div>
260
  """
261
 
262
- # Devolver el HTML y el archivo CSV
263
- return html_output, csv_file
264
 
265
- # Interfaz de Gradio con salida HTML y archivo descargable (CSV)
266
  iface = gr.Interface(
267
  fn=main,
268
  inputs="text",
269
- outputs=[gr.HTML(), gr.File(label="Descargar CSV")],
270
- 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>",
271
- 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>",
272
- 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>"
273
  )
274
 
275
  iface.launch()
 
5
  import xmltodict
6
  from collections import Counter
7
  import unicodedata
 
8
 
9
  # Función para normalizar palabras clave (elimina tildes y convierte a minúsculas)
10
  def normalize_keyword(keyword):
 
165
  suggestion_counter = Counter(suggestions)
166
  return suggestion_counter.most_common(top_n)
167
 
168
+ # Función principal que muestra el top 10 combinado, top 3 de cada plataforma y una tabla completa
169
  def main(keyword):
170
  expanded_keywords = expand_keyword(keyword)
171
  all_suggestions = {}
 
228
  for suggestion in suggestions:
229
  all_suggestions[suggestion] = all_suggestions.get(suggestion, 0) + 1
230
 
231
+ # Obtener las top 10 sugerencias combinadas
232
+ combined_top_10 = get_top_suggestions(all_suggestions, top_n=10)
 
 
 
 
 
 
233
 
234
+ # Obtener las top 3 de cada plataforma
235
+ google_top_3 = get_top_suggestions(google_suggestions_all, top_n=3)
236
+ duckduckgo_top_3 = get_top_suggestions(duckduckgo_suggestions_all, top_n=3)
237
+ youtube_top_3 = get_top_suggestions(youtube_suggestions_all, top_n=3)
238
+ bing_top_3 = get_top_suggestions(bing_suggestions_all, top_n=3)
239
+ amazon_top_3 = get_top_suggestions(amazon_suggestions_all, top_n=3)
240
+ qwant_top_3 = get_top_suggestions(qwant_suggestions_all, top_n=3)
241
+ brave_top_3 = get_top_suggestions(brave_suggestions_all, top_n=3)
242
 
243
+ # Crear una tabla con todas las sugerencias y su número de repeticiones
244
+ all_suggestions_str = "<table><tr><th>Keyword</th><th>Relevancia</th></tr>"
245
+ for suggestion, freq in sorted(all_suggestions.items(), key=lambda item: item[1], reverse=True):
246
+ all_suggestions_str += f"<tr><td>{suggestion}</td><td>{freq}</td></tr>"
247
+ all_suggestions_str += "</table>"
248
 
249
+ # Crear el HTML de salida
 
 
 
 
250
  html_output = f"""
251
  <div>
252
+ <h3>Top 10 combinadas:</h3>
253
+ <ul>
254
+ {''.join([f'<li>{sug} ({freq})</li>' for sug, freq in combined_top_10])}
255
+ </ul>
256
+
257
+ <h4>Top 3 Sugerencias de Google:</h4>
258
+ <ul>
259
+ {''.join([f'<li>{sug} ({freq})</li>' for sug, freq in google_top_3])}
260
+ </ul>
261
+
262
+ <h4>Top 3 Sugerencias de DuckDuckGo:</h4>
263
+ <ul>
264
+ {''.join([f'<li>{sug} ({freq})</li>' for sug, freq in duckduckgo_top_3])}
265
+ </ul>
266
+
267
+ <h4>Top 3 Sugerencias de YouTube:</h4>
268
+ <ul>
269
+ {''.join([f'<li>{sug} ({freq})</li>' for sug, freq in youtube_top_3])}
270
+ </ul>
271
+
272
+ <h4>Top 3 Sugerencias de Bing:</h4>
273
+ <ul>
274
+ {''.join([f'<li>{sug} ({freq})</li>' for sug, freq in bing_top_3])}
275
+ </ul>
276
+
277
+ <h4>Top 3 Sugerencias de Amazon:</h4>
278
+ <ul>
279
+ {''.join([f'<li>{sug} ({freq})</li>' for sug, freq in amazon_top_3])}
280
+ </ul>
281
+
282
+ <h4>Top 3 Sugerencias de Qwant:</h4>
283
+ <ul>
284
+ {''.join([f'<li>{sug} ({freq})</li>' for sug, freq in qwant_top_3])}
285
+ </ul>
286
+
287
+ <h4>Top 3 Sugerencias de Brave:</h4>
288
+ <ul>
289
+ {''.join([f'<li>{sug} ({freq})</li>' for sug, freq in brave_top_3])}
290
+ </ul>
291
+
292
+ <h4>Tabla completa de palabras clave y su relevancia:</h4>
293
+ {all_suggestions_str}
294
  </div>
295
  """
296
 
297
+ return html_output
 
298
 
299
+ # Interfaz de Gradio
300
  iface = gr.Interface(
301
  fn=main,
302
  inputs="text",
303
+ outputs=gr.HTML(),
304
+ title="Sugerencias Combinadas de Múltiples Motores de Búsqueda",
305
+ description="Ingrese una palabra clave para obtener sugerencias de búsqueda relacionadas de Google, DuckDuckGo, YouTube, Bing, Amazon, Qwant y Brave.",
 
306
  )
307
 
308
  iface.launch()