Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ logger = logging.getLogger(__name__)
|
|
13 |
|
14 |
def setup_spacy_model() -> None:
|
15 |
"""
|
16 |
-
Verifica y descarga el modelo
|
17 |
"""
|
18 |
try:
|
19 |
spacy.load("es_core_news_lg")
|
@@ -40,24 +40,25 @@ def list_content_storage_files() -> list:
|
|
40 |
base_dir = Path("content_storage")
|
41 |
if not base_dir.exists():
|
42 |
return []
|
43 |
-
# Se recorren recursivamente todos los archivos
|
44 |
file_list = [str(file.relative_to(base_dir)) for file in base_dir.glob("**/*") if file.is_file()]
|
|
|
45 |
return file_list
|
46 |
|
47 |
def download_storage_file(selected_file: str) -> str:
|
48 |
"""
|
49 |
Dado el nombre de un archivo (ruta relativa respecto a content_storage),
|
50 |
-
devuelve la ruta completa del archivo para
|
51 |
"""
|
52 |
if not selected_file:
|
53 |
return ""
|
54 |
file_path = Path("content_storage") / selected_file
|
55 |
-
|
|
|
|
|
|
|
56 |
|
57 |
def refresh_file_list() -> list:
|
58 |
-
"""
|
59 |
-
Funci贸n para refrescar la lista de archivos disponibles en content_storage.
|
60 |
-
"""
|
61 |
return list_content_storage_files()
|
62 |
|
63 |
def create_interface() -> gr.Blocks:
|
@@ -73,7 +74,7 @@ def create_interface() -> gr.Blocks:
|
|
73 |
with gr.Column():
|
74 |
sitemap_input = gr.Textbox(
|
75 |
label="URL del Sitemap",
|
76 |
-
placeholder="https://
|
77 |
interactive=True
|
78 |
)
|
79 |
analyze_btn = gr.Button("Analizar Sitio", variant="primary")
|
@@ -100,12 +101,22 @@ def create_interface() -> gr.Blocks:
|
|
100 |
download_file_btn = gr.Button("Descargar Archivo Seleccionado", variant="secondary")
|
101 |
file_download = gr.File(label="Archivo Seleccionado")
|
102 |
def generate_report() -> str:
|
|
|
|
|
|
|
103 |
if analyzer.current_analysis:
|
104 |
report_path = "content_storage/seo_report.json"
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
def plot_internal_links(links_json: dict) -> any:
|
110 |
return analyzer.plot_internal_links(links_json)
|
111 |
analyze_btn.click(
|
|
|
13 |
|
14 |
def setup_spacy_model() -> None:
|
15 |
"""
|
16 |
+
Verifica y descarga el modelo spaCy 'es_core_news_lg' si no est谩 instalado.
|
17 |
"""
|
18 |
try:
|
19 |
spacy.load("es_core_news_lg")
|
|
|
40 |
base_dir = Path("content_storage")
|
41 |
if not base_dir.exists():
|
42 |
return []
|
|
|
43 |
file_list = [str(file.relative_to(base_dir)) for file in base_dir.glob("**/*") if file.is_file()]
|
44 |
+
logger.info(f"Archivos encontrados en content_storage: {file_list}")
|
45 |
return file_list
|
46 |
|
47 |
def download_storage_file(selected_file: str) -> str:
|
48 |
"""
|
49 |
Dado el nombre de un archivo (ruta relativa respecto a content_storage),
|
50 |
+
devuelve la ruta completa del archivo para descargarlo.
|
51 |
"""
|
52 |
if not selected_file:
|
53 |
return ""
|
54 |
file_path = Path("content_storage") / selected_file
|
55 |
+
if file_path.exists():
|
56 |
+
return str(file_path)
|
57 |
+
else:
|
58 |
+
return ""
|
59 |
|
60 |
def refresh_file_list() -> list:
|
61 |
+
"""Funci贸n para actualizar la lista de archivos en content_storage."""
|
|
|
|
|
62 |
return list_content_storage_files()
|
63 |
|
64 |
def create_interface() -> gr.Blocks:
|
|
|
74 |
with gr.Column():
|
75 |
sitemap_input = gr.Textbox(
|
76 |
label="URL del Sitemap",
|
77 |
+
placeholder="https://ejemplo.com/sitemap.xml",
|
78 |
interactive=True
|
79 |
)
|
80 |
analyze_btn = gr.Button("Analizar Sitio", variant="primary")
|
|
|
101 |
download_file_btn = gr.Button("Descargar Archivo Seleccionado", variant="secondary")
|
102 |
file_download = gr.File(label="Archivo Seleccionado")
|
103 |
def generate_report() -> str:
|
104 |
+
"""
|
105 |
+
Genera un informe en formato JSON con el an谩lisis SEO y lo guarda en content_storage.
|
106 |
+
"""
|
107 |
if analyzer.current_analysis:
|
108 |
report_path = "content_storage/seo_report.json"
|
109 |
+
try:
|
110 |
+
with open(report_path, 'w', encoding='utf-8') as f:
|
111 |
+
json.dump(analyzer.current_analysis, f, indent=2, ensure_ascii=False)
|
112 |
+
logger.info(f"Reporte generado en: {report_path}")
|
113 |
+
return report_path
|
114 |
+
except Exception as e:
|
115 |
+
logger.error(f"Error generando reporte: {e}")
|
116 |
+
return ""
|
117 |
+
else:
|
118 |
+
logger.warning("No hay an谩lisis para generar el reporte.")
|
119 |
+
return ""
|
120 |
def plot_internal_links(links_json: dict) -> any:
|
121 |
return analyzer.plot_internal_links(links_json)
|
122 |
analyze_btn.click(
|