Merlintxu commited on
Commit
90799a0
verified
1 Parent(s): 52bfade

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -1
app.py CHANGED
@@ -5,6 +5,8 @@ import spacy
5
  import subprocess
6
  import sys
7
  import logging
 
 
8
 
9
  logging.basicConfig(level=logging.INFO)
10
  logger = logging.getLogger(__name__)
@@ -30,6 +32,34 @@ def setup_spacy_model() -> None:
30
  logger.error(f"Error al descargar modelo: {e.stderr.decode()}")
31
  raise RuntimeError("No se pudo descargar el modelo spaCy") from e
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  def create_interface() -> gr.Blocks:
34
  analyzer = SEOSpaceAnalyzer()
35
  with gr.Blocks(title="SEO Analyzer Pro", theme=gr.themes.Soft()) as interface:
@@ -43,7 +73,7 @@ def create_interface() -> gr.Blocks:
43
  with gr.Column():
44
  sitemap_input = gr.Textbox(
45
  label="URL del Sitemap",
46
- placeholder="npm install firebase",
47
  interactive=True
48
  )
49
  analyze_btn = gr.Button("Analizar Sitio", variant="primary")
@@ -64,6 +94,11 @@ def create_interface() -> gr.Blocks:
64
  links_plot = gr.Plot(label="Visualizaci贸n de Enlaces Internos")
65
  with gr.Tab("馃搫 Detalles"):
66
  details_output = gr.JSON(label="Detalles Individuales")
 
 
 
 
 
67
  def generate_report() -> str:
68
  if analyzer.current_analysis:
69
  report_path = "content_storage/seo_report.json"
@@ -92,6 +127,15 @@ def create_interface() -> gr.Blocks:
92
  inputs=links_output,
93
  outputs=links_plot
94
  )
 
 
 
 
 
 
 
 
 
95
  return interface
96
 
97
  if __name__ == "__main__":
 
5
  import subprocess
6
  import sys
7
  import logging
8
+ import os
9
+ from pathlib import Path
10
 
11
  logging.basicConfig(level=logging.INFO)
12
  logger = logging.getLogger(__name__)
 
32
  logger.error(f"Error al descargar modelo: {e.stderr.decode()}")
33
  raise RuntimeError("No se pudo descargar el modelo spaCy") from e
34
 
35
+ def list_content_storage_files() -> list:
36
+ """
37
+ Busca todos los archivos dentro de la carpeta content_storage y
38
+ devuelve una lista de rutas relativas.
39
+ """
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 que se pueda descargar.
51
+ """
52
+ if not selected_file:
53
+ return ""
54
+ file_path = Path("content_storage") / selected_file
55
+ return str(file_path)
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:
64
  analyzer = SEOSpaceAnalyzer()
65
  with gr.Blocks(title="SEO Analyzer Pro", theme=gr.themes.Soft()) as interface:
 
73
  with gr.Column():
74
  sitemap_input = gr.Textbox(
75
  label="URL del Sitemap",
76
+ placeholder="https://www.ing.es/ennaranja/sitemap.xml",
77
  interactive=True
78
  )
79
  analyze_btn = gr.Button("Analizar Sitio", variant="primary")
 
94
  links_plot = gr.Plot(label="Visualizaci贸n de Enlaces Internos")
95
  with gr.Tab("馃搫 Detalles"):
96
  details_output = gr.JSON(label="Detalles Individuales")
97
+ with gr.Tab("馃搧 Archivos"):
98
+ file_dropdown = gr.Dropdown(label="Archivos en content_storage", choices=list_content_storage_files())
99
+ refresh_btn = gr.Button("Actualizar lista")
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"
 
127
  inputs=links_output,
128
  outputs=links_plot
129
  )
130
+ refresh_btn.click(
131
+ fn=refresh_file_list,
132
+ outputs=file_dropdown
133
+ )
134
+ download_file_btn.click(
135
+ fn=download_storage_file,
136
+ inputs=file_dropdown,
137
+ outputs=file_download
138
+ )
139
  return interface
140
 
141
  if __name__ == "__main__":