Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
from bs4 import BeautifulSoup
|
4 |
-
from itertools import combinations
|
5 |
from urllib.parse import quote
|
6 |
|
7 |
# Paleta de colores
|
@@ -31,27 +30,30 @@ def buscar_google(query, hl='es', num_results=10):
|
|
31 |
return serp_data
|
32 |
|
33 |
def generar_html_con_colores(keywords):
|
34 |
-
|
|
|
|
|
|
|
|
|
35 |
html_table = "<style>td, th {border: 1px solid #ddd; text-align: left; padding: 8px;} tr:nth-child(even) {background-color: #f2f2f2;} th {padding-top: 11px; padding-bottom: 11px; background-color: #4CAF50; color: white;}</style>"
|
36 |
html_table += "<table><tr><th>Posici贸n</th>"
|
37 |
|
38 |
-
for keyword in
|
39 |
html_table += f"<th>{keyword.strip()}</th>"
|
40 |
html_table += "</tr>"
|
41 |
|
42 |
url_colors = {}
|
43 |
-
max_length = max(len(serp_results[keyword.strip()]) for keyword in keywords.split(','))
|
44 |
-
|
45 |
for i in range(max_length):
|
46 |
-
html_table += "<tr><td>{}</td>"
|
47 |
-
for keyword in
|
48 |
keyword = keyword.strip()
|
49 |
-
|
50 |
-
|
|
|
51 |
if url not in url_colors:
|
52 |
url_colors[url] = color_palette[len(url_colors) % len(color_palette)]
|
53 |
color = url_colors[url]
|
54 |
-
html_table += "<td><span style='color:{}'>{}</span></td>"
|
55 |
else:
|
56 |
html_table += "<td></td>"
|
57 |
html_table += "</tr>"
|
@@ -66,4 +68,4 @@ iface = gr.Interface(
|
|
66 |
description="Introduce las keywords separadas por comas para encontrar coincidencias en los resultados de b煤squeda de Google."
|
67 |
)
|
68 |
|
69 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
from bs4 import BeautifulSoup
|
|
|
4 |
from urllib.parse import quote
|
5 |
|
6 |
# Paleta de colores
|
|
|
30 |
return serp_data
|
31 |
|
32 |
def generar_html_con_colores(keywords):
|
33 |
+
keywords_list = keywords.split(',')
|
34 |
+
serp_results = {keyword.strip(): buscar_google(keyword.strip()) for keyword in keywords_list}
|
35 |
+
|
36 |
+
max_length = max(len(results) for results in serp_results.values()) if serp_results else 0
|
37 |
+
|
38 |
html_table = "<style>td, th {border: 1px solid #ddd; text-align: left; padding: 8px;} tr:nth-child(even) {background-color: #f2f2f2;} th {padding-top: 11px; padding-bottom: 11px; background-color: #4CAF50; color: white;}</style>"
|
39 |
html_table += "<table><tr><th>Posici贸n</th>"
|
40 |
|
41 |
+
for keyword in keywords_list:
|
42 |
html_table += f"<th>{keyword.strip()}</th>"
|
43 |
html_table += "</tr>"
|
44 |
|
45 |
url_colors = {}
|
|
|
|
|
46 |
for i in range(max_length):
|
47 |
+
html_table += f"<tr><td>{i + 1}</td>"
|
48 |
+
for keyword in keywords_list:
|
49 |
keyword = keyword.strip()
|
50 |
+
results = serp_results.get(keyword, [])
|
51 |
+
if i < len(results):
|
52 |
+
url = results[i]["URL"]
|
53 |
if url not in url_colors:
|
54 |
url_colors[url] = color_palette[len(url_colors) % len(color_palette)]
|
55 |
color = url_colors[url]
|
56 |
+
html_table += f"<td><span style='color:{color}'>{results[i]['T铆tulo']}</span></td>"
|
57 |
else:
|
58 |
html_table += "<td></td>"
|
59 |
html_table += "</tr>"
|
|
|
68 |
description="Introduce las keywords separadas por comas para encontrar coincidencias en los resultados de b煤squeda de Google."
|
69 |
)
|
70 |
|
71 |
+
iface.launch()
|