Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
from pathlib import Path
|
| 4 |
import tempfile
|
|
|
|
| 5 |
|
| 6 |
class WebProjectAnalyzer:
|
| 7 |
def __init__(self):
|
|
@@ -12,88 +13,150 @@ class WebProjectAnalyzer:
|
|
| 12 |
'coverage', '.github', '.circleci', '.docker', 'venv',
|
| 13 |
'env', '.venv', 'virtualenv', 'bin', 'include', 'lib',
|
| 14 |
'lib64', 'site-packages', 'dist-packages', '.gitlab',
|
| 15 |
-
'.svn', '.hg', '.pytest_cache', '.mypy_cache', '__MACOSX'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
-
# Extensões relevantes para projetos web
|
| 19 |
self.relevant_extensions = {
|
| 20 |
-
|
| 21 |
-
'.
|
| 22 |
-
'.
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
}
|
| 25 |
|
| 26 |
-
# Arquivos de configuração
|
| 27 |
-
self.
|
| 28 |
-
'package.json', '
|
| 29 |
-
'
|
| 30 |
-
'
|
| 31 |
-
'
|
| 32 |
-
'.
|
| 33 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
}
|
| 35 |
|
| 36 |
-
def should_ignore(self, name, path):
|
| 37 |
"""Determina se um arquivo/diretório deve ser ignorado"""
|
| 38 |
# Ignora diretórios específicos
|
| 39 |
-
if name in self.ignored_dirs:
|
| 40 |
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
# Ignora arquivos ocultos (
|
| 43 |
-
if name.startswith('.') and name not in self.
|
| 44 |
-
|
| 45 |
-
if not any(name.endswith(ext) for ext in ['.env.example', '.gitattributes', '.editorconfig']):
|
| 46 |
return True
|
| 47 |
-
|
| 48 |
# Ignora arquivos temporários
|
| 49 |
-
if name.endswith('~') or name.startswith('~'):
|
| 50 |
-
return True
|
| 51 |
-
|
| 52 |
-
# Ignora pastas de ambiente Python
|
| 53 |
-
if any(env_dir in path.split(os.sep) for env_dir in ['venv', 'virtualenv', '.venv']):
|
| 54 |
return True
|
| 55 |
-
|
| 56 |
-
# Ignora
|
| 57 |
-
if any(
|
| 58 |
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
return False
|
| 61 |
|
| 62 |
-
def is_relevant_file(self, name):
|
| 63 |
"""Determina se um arquivo é relevante para mostrar"""
|
| 64 |
-
# Arquivos
|
| 65 |
-
if name in self.
|
| 66 |
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
# Verifica extensões relevantes
|
| 69 |
_, ext = os.path.splitext(name)
|
| 70 |
return ext.lower() in self.relevant_extensions
|
| 71 |
|
| 72 |
-
def get_file_icon(self, filename):
|
| 73 |
"""Retorna ícone apropriado para o tipo de arquivo"""
|
| 74 |
_, ext = os.path.splitext(filename)
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
icon_map = {
|
| 77 |
'.py': '🐍', '.js': '📜', '.jsx': '⚛️', '.ts': '📘', '.tsx': '⚛️',
|
| 78 |
'.html': '🌐', '.htm': '🌐', '.css': '🎨', '.scss': '🎨', '.less': '🎨',
|
| 79 |
'.php': '🐘', '.java': '☕', '.rb': '💎', '.json': '📋', '.xml': '📄',
|
| 80 |
'.sql': '🗃️', '.md': '📖', '.txt': '📄', '.yml': '⚙️', '.yaml': '⚙️',
|
| 81 |
-
'.toml': '⚙️', '.
|
| 82 |
-
'.vue': '💚', '.svelte': '🟢', '.rust': '🦀', '.go': '🐹'
|
| 83 |
}
|
| 84 |
|
| 85 |
return icon_map.get(ext, '📄')
|
| 86 |
|
| 87 |
-
def analyze_structure(self, root_path, max_depth=4):
|
| 88 |
"""Analisa a estrutura do projeto"""
|
| 89 |
if not root_path:
|
| 90 |
-
return "❌
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
if not os.path.exists(root_path):
|
| 93 |
return "❌ Pasta não encontrada.", {"total_files": 0, "relevant_files": 0, "total_size": 0}, []
|
| 94 |
|
| 95 |
if not os.path.isdir(root_path):
|
| 96 |
-
return "❌
|
| 97 |
|
| 98 |
structure_output = []
|
| 99 |
relevant_files = []
|
|
@@ -103,11 +166,9 @@ class WebProjectAnalyzer:
|
|
| 103 |
'total_size': 0
|
| 104 |
}
|
| 105 |
|
| 106 |
-
def analyze_directory(current_path, level=0):
|
| 107 |
if level > max_depth:
|
| 108 |
return
|
| 109 |
-
|
| 110 |
-
indent = ' ' * level
|
| 111 |
|
| 112 |
try:
|
| 113 |
items = sorted(os.listdir(current_path))
|
|
@@ -115,279 +176,170 @@ class WebProjectAnalyzer:
|
|
| 115 |
dirs = []
|
| 116 |
files = []
|
| 117 |
|
|
|
|
| 118 |
for item in items:
|
| 119 |
full_path = os.path.join(current_path, item)
|
|
|
|
| 120 |
|
| 121 |
-
if self.should_ignore(item, full_path):
|
| 122 |
continue
|
| 123 |
-
|
| 124 |
-
if
|
| 125 |
dirs.append(item)
|
| 126 |
else:
|
| 127 |
-
files.append(item)
|
| 128 |
-
|
| 129 |
stats['total_files'] += 1
|
| 130 |
if self.is_relevant_file(item):
|
|
|
|
| 131 |
stats['relevant_files'] += 1
|
| 132 |
relevant_files.append(full_path)
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
|
| 139 |
-
#
|
| 140 |
-
for file in files:
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
| 144 |
|
| 145 |
-
#
|
| 146 |
-
for dir_name in dirs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
full_path = os.path.join(current_path, dir_name)
|
| 148 |
-
|
| 149 |
-
analyze_directory(full_path, level + 1)
|
| 150 |
|
| 151 |
except PermissionError:
|
| 152 |
-
structure_output.append(f"{
|
| 153 |
except Exception as e:
|
| 154 |
-
structure_output.append(f"{
|
| 155 |
|
| 156 |
try:
|
| 157 |
-
|
|
|
|
|
|
|
| 158 |
|
| 159 |
-
|
|
|
|
|
|
|
| 160 |
return "ℹ️ Nenhum arquivo relevante encontrado na pasta selecionada.", stats, relevant_files
|
| 161 |
-
|
| 162 |
structure_text = '\n'.join(structure_output)
|
| 163 |
return structure_text, stats, relevant_files
|
| 164 |
|
| 165 |
except Exception as e:
|
| 166 |
-
return f"❌ Erro ao analisar
|
| 167 |
|
| 168 |
-
def create_structure_report(self, folder_path, structure, stats
|
| 169 |
"""Cria relatório completo da estrutura"""
|
| 170 |
total_files = stats['total_files']
|
| 171 |
-
|
| 172 |
total_size = stats['total_size']
|
| 173 |
|
| 174 |
folder_name = os.path.basename(folder_path)
|
| 175 |
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
📍 **Pasta**: {folder_path}
|
| 183 |
|
| 184 |
-
📈
|
| 185 |
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
|
|
|
| 191 |
|
| 192 |
-
|
| 193 |
|
|
|
|
|
|
|
|
|
|
| 194 |
{structure}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
-
|
| 197 |
-
-
|
| 198 |
-
-
|
| 199 |
-
-
|
| 200 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
"""
|
| 202 |
return report
|
| 203 |
|
| 204 |
-
def
|
| 205 |
-
"""Processa
|
| 206 |
-
if not
|
| 207 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
try:
|
| 210 |
-
#
|
| 211 |
-
if isinstance(
|
| 212 |
-
|
| 213 |
else:
|
| 214 |
-
|
| 215 |
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
# Analisa estrutura
|
| 225 |
-
structure, stats, relevant_files = self.analyze_structure(
|
| 226 |
|
| 227 |
# Cria relatório
|
| 228 |
-
report = self.create_structure_report(
|
| 229 |
|
| 230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
except Exception as e:
|
| 233 |
error_msg = f"❌ Erro ao processar: {str(e)}"
|
| 234 |
-
return error_msg, "",
|
| 235 |
-
|
| 236 |
-
def analyze_demo_projects(self, project_type):
|
| 237 |
-
"""Fornece exemplos de estruturas de projetos"""
|
| 238 |
-
demos = {
|
| 239 |
-
"react": """
|
| 240 |
-
meu-app-react/
|
| 241 |
-
📁 src/
|
| 242 |
-
📁 components/
|
| 243 |
-
📄 Header.js
|
| 244 |
-
📄 Footer.js
|
| 245 |
-
📁 ui/
|
| 246 |
-
📄 Button.js
|
| 247 |
-
📄 Card.js
|
| 248 |
-
📁 pages/
|
| 249 |
-
📄 Home.js
|
| 250 |
-
📄 About.js
|
| 251 |
-
📄 Contact.js
|
| 252 |
-
📁 hooks/
|
| 253 |
-
📄 useAuth.js
|
| 254 |
-
📄 useAPI.js
|
| 255 |
-
📁 utils/
|
| 256 |
-
📄 helpers.js
|
| 257 |
-
📄 constants.js
|
| 258 |
-
📄 App.js
|
| 259 |
-
📄 index.js
|
| 260 |
-
📄 App.css
|
| 261 |
-
📁 public/
|
| 262 |
-
📄 index.html
|
| 263 |
-
📄 favicon.ico
|
| 264 |
-
📄 manifest.json
|
| 265 |
-
📄 package.json
|
| 266 |
-
📄 README.md
|
| 267 |
-
📄 .gitignore
|
| 268 |
-
""",
|
| 269 |
-
|
| 270 |
-
"django": """
|
| 271 |
-
meu-projeto-django/
|
| 272 |
-
📁 myproject/
|
| 273 |
-
📁 settings/
|
| 274 |
-
📄 __init__.py
|
| 275 |
-
📄 base.py
|
| 276 |
-
📄 development.py
|
| 277 |
-
📄 production.py
|
| 278 |
-
📁 urls.py
|
| 279 |
-
📁 wsgi.py
|
| 280 |
-
📁 apps/
|
| 281 |
-
📁 users/
|
| 282 |
-
📁 migrations/
|
| 283 |
-
📄 __init__.py
|
| 284 |
-
📁 templates/
|
| 285 |
-
📄 base.html
|
| 286 |
-
📄 login.html
|
| 287 |
-
📄 admin.py
|
| 288 |
-
📄 models.py
|
| 289 |
-
📄 views.py
|
| 290 |
-
📄 urls.py
|
| 291 |
-
📁 blog/
|
| 292 |
-
📁 migrations/
|
| 293 |
-
📄 __init__.py
|
| 294 |
-
📁 templates/
|
| 295 |
-
📄 post_list.html
|
| 296 |
-
📄 admin.py
|
| 297 |
-
📄 models.py
|
| 298 |
-
📄 views.py
|
| 299 |
-
📁 static/
|
| 300 |
-
📁 css/
|
| 301 |
-
📄 style.css
|
| 302 |
-
📁 js/
|
| 303 |
-
📄 main.js
|
| 304 |
-
📁 templates/
|
| 305 |
-
📄 base.html
|
| 306 |
-
📄 manage.py
|
| 307 |
-
📄 requirements.txt
|
| 308 |
-
📄 README.md
|
| 309 |
-
🐍 .env.example
|
| 310 |
-
""",
|
| 311 |
-
|
| 312 |
-
"vue": """
|
| 313 |
-
meu-app-vue/
|
| 314 |
-
📁 src/
|
| 315 |
-
📁 components/
|
| 316 |
-
📄 Navigation.vue
|
| 317 |
-
📄 Sidebar.vue
|
| 318 |
-
📄 Modal.vue
|
| 319 |
-
📁 views/
|
| 320 |
-
📄 Home.vue
|
| 321 |
-
📄 About.vue
|
| 322 |
-
📄 Contact.vue
|
| 323 |
-
📁 router/
|
| 324 |
-
📄 index.js
|
| 325 |
-
📁 store/
|
| 326 |
-
📄 index.js
|
| 327 |
-
📄 modules/
|
| 328 |
-
📄 user.js
|
| 329 |
-
📁 assets/
|
| 330 |
-
📁 css/
|
| 331 |
-
📄 main.css
|
| 332 |
-
📁 images/
|
| 333 |
-
📄 main.js
|
| 334 |
-
📄 App.vue
|
| 335 |
-
📁 public/
|
| 336 |
-
📄 index.html
|
| 337 |
-
📄 package.json
|
| 338 |
-
📄 vue.config.js
|
| 339 |
-
📄 README.md
|
| 340 |
-
""",
|
| 341 |
-
|
| 342 |
-
"nodejs": """
|
| 343 |
-
meu-app-nodejs/
|
| 344 |
-
📁 src/
|
| 345 |
-
📁 controllers/
|
| 346 |
-
📄 userController.js
|
| 347 |
-
📄 productController.js
|
| 348 |
-
📁 models/
|
| 349 |
-
📄 User.js
|
| 350 |
-
📄 Product.js
|
| 351 |
-
📁 routes/
|
| 352 |
-
📄 auth.js
|
| 353 |
-
📄 users.js
|
| 354 |
-
📄 products.js
|
| 355 |
-
📁 middleware/
|
| 356 |
-
📄 auth.js
|
| 357 |
-
📄 validation.js
|
| 358 |
-
📁 utils/
|
| 359 |
-
📄 database.js
|
| 360 |
-
📄 logger.js
|
| 361 |
-
📄 app.js
|
| 362 |
-
📄 server.js
|
| 363 |
-
📁 config/
|
| 364 |
-
📄 database.js
|
| 365 |
-
📄 environment.js
|
| 366 |
-
📁 tests/
|
| 367 |
-
📄 user.test.js
|
| 368 |
-
📄 product.test.js
|
| 369 |
-
📄 package.json
|
| 370 |
-
📄 .env.example
|
| 371 |
-
📄 README.md
|
| 372 |
-
"""
|
| 373 |
-
}
|
| 374 |
-
|
| 375 |
-
if project_type in demos:
|
| 376 |
-
return f"""
|
| 377 |
-
📊 **EXEMPLO: {project_type.upper()}**
|
| 378 |
-
|
| 379 |
-
{demos[project_type]}
|
| 380 |
-
|
| 381 |
-
💡 **Como funcionaria com uma pasta real:**
|
| 382 |
-
- 📁 Pasta selecionada: `meu-app-{project_type}/`
|
| 383 |
-
- 📄 Arquivos relevantes detectados: ~15-30 arquivos
|
| 384 |
-
- 🎯 Apenas código e configurações seriam analisados
|
| 385 |
-
- 🚫 node_modules, .git, cache seriam ignorados
|
| 386 |
-
"""
|
| 387 |
-
else:
|
| 388 |
-
return "❌ Tipo de projeto não encontrado."
|
| 389 |
|
| 390 |
-
# ================== Gradio Interface ==================
|
| 391 |
|
| 392 |
def create_interface():
|
| 393 |
"""Cria a interface Gradio"""
|
|
@@ -395,316 +347,122 @@ def create_interface():
|
|
| 395 |
analyzer = WebProjectAnalyzer()
|
| 396 |
|
| 397 |
with gr.Blocks(
|
| 398 |
-
title="Web Project Structure Analyzer",
|
| 399 |
-
theme=gr.themes.Soft(),
|
| 400 |
-
|
| 401 |
-
.gradio-container {
|
| 402 |
-
max-width: 1200px !important;
|
| 403 |
-
}
|
| 404 |
-
.header {
|
| 405 |
-
text-align: center;
|
| 406 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 407 |
-
padding: 25px;
|
| 408 |
-
border-radius: 15px;
|
| 409 |
-
color: white;
|
| 410 |
-
margin-bottom: 25px;
|
| 411 |
-
}
|
| 412 |
-
.upload-box {
|
| 413 |
-
border: 2px dashed #007bff;
|
| 414 |
-
padding: 30px;
|
| 415 |
-
border-radius: 10px;
|
| 416 |
-
text-align: center;
|
| 417 |
-
background: #f8f9fa;
|
| 418 |
-
margin: 15px 0;
|
| 419 |
-
}
|
| 420 |
-
.structure-box {
|
| 421 |
-
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
| 422 |
-
font-size: 12px;
|
| 423 |
-
line-height: 1.4;
|
| 424 |
-
background: #f8f9fa;
|
| 425 |
-
padding: 20px;
|
| 426 |
-
border-radius: 10px;
|
| 427 |
-
border: 1px solid #dee2e6;
|
| 428 |
-
}
|
| 429 |
-
.stats-card {
|
| 430 |
-
background: white;
|
| 431 |
-
padding: 15px;
|
| 432 |
-
border-radius: 8px;
|
| 433 |
-
border: 1px solid #dee2e6;
|
| 434 |
-
margin: 10px 0;
|
| 435 |
-
}
|
| 436 |
-
.error-box {
|
| 437 |
-
background: #ffe6e6;
|
| 438 |
-
border: 2px solid #ff4444;
|
| 439 |
-
padding: 15px;
|
| 440 |
-
border-radius: 8px;
|
| 441 |
-
margin: 10px 0;
|
| 442 |
-
}
|
| 443 |
-
.success-box {
|
| 444 |
-
background: #e6ffe6;
|
| 445 |
-
border: 2px solid #44ff44;
|
| 446 |
-
padding: 15px;
|
| 447 |
-
border-radius: 8px;
|
| 448 |
-
margin: 10px 0;
|
| 449 |
-
}
|
| 450 |
-
"""
|
| 451 |
-
) as interface:
|
| 452 |
-
|
| 453 |
-
gr.Markdown(
|
| 454 |
-
"""
|
| 455 |
-
<div class="header">
|
| 456 |
-
<h1>🔍 Web Project Structure Analyzer</h1>
|
| 457 |
-
<p>Selecione uma PASTA completa do projeto para analisar sua estrutura</p>
|
| 458 |
-
</div>
|
| 459 |
-
"""
|
| 460 |
-
)
|
| 461 |
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
folder_input = gr.File(
|
| 479 |
-
label="Clique aqui para selecionar uma PASTA do projeto",
|
| 480 |
-
file_count="directory",
|
| 481 |
-
type="filepath",
|
| 482 |
-
height=120
|
| 483 |
-
)
|
| 484 |
-
|
| 485 |
-
with gr.Group():
|
| 486 |
-
gr.Markdown("### ⚙️ Configurações")
|
| 487 |
-
|
| 488 |
-
max_depth = gr.Slider(
|
| 489 |
-
minimum=1,
|
| 490 |
-
maximum=6,
|
| 491 |
-
value=4,
|
| 492 |
-
step=1,
|
| 493 |
-
label="Profundidade de Análise",
|
| 494 |
-
info="Níveis de subpastas a serem escaneados"
|
| 495 |
-
)
|
| 496 |
-
|
| 497 |
-
analyze_btn = gr.Button(
|
| 498 |
-
"🔍 Analisar Estrutura",
|
| 499 |
-
variant="primary",
|
| 500 |
-
size="lg"
|
| 501 |
-
)
|
| 502 |
-
|
| 503 |
-
with gr.Accordion("📋 O que será analisado", open=True):
|
| 504 |
-
gr.Markdown("""
|
| 505 |
-
**✅ ARQUIVOS INCLUÍDOS:**
|
| 506 |
-
- 🐍 Código fonte (.py, .js, .html, .css)
|
| 507 |
-
- ⚙️ Arquivos de configuração
|
| 508 |
-
- 📖 Documentação (.md, .txt)
|
| 509 |
-
- 🛠️ Configurações de projeto
|
| 510 |
-
|
| 511 |
-
**🚫 ARQUIVOS IGNORADOS:**
|
| 512 |
-
- 📦 node_modules, .git, venv
|
| 513 |
-
- 🗑️ Arquivos de cache
|
| 514 |
-
- 🔧 Dependências
|
| 515 |
-
- 📊 Logs e builds
|
| 516 |
-
- ⏰ Arquivos temporários
|
| 517 |
-
""")
|
| 518 |
-
|
| 519 |
-
with gr.Column(scale=2):
|
| 520 |
-
gr.Markdown("### 📊 Resultado da Análise")
|
| 521 |
-
|
| 522 |
-
# Estatísticas
|
| 523 |
-
stats_display = gr.Markdown(
|
| 524 |
-
label="Estatísticas da Análise",
|
| 525 |
-
elem_classes=["stats-card"]
|
| 526 |
-
)
|
| 527 |
-
|
| 528 |
-
# Estrutura
|
| 529 |
-
output_structure = gr.Textbox(
|
| 530 |
-
label="Estrutura do Projeto",
|
| 531 |
-
lines=15,
|
| 532 |
-
show_copy_button=True,
|
| 533 |
-
elem_classes=["structure-box"]
|
| 534 |
-
)
|
| 535 |
-
|
| 536 |
-
# Botões de ação
|
| 537 |
-
with gr.Row():
|
| 538 |
-
export_btn = gr.Button("💾 Exportar Relatório", variant="secondary")
|
| 539 |
-
clear_btn = gr.Button("🗑️ Nova Análise", variant="secondary")
|
| 540 |
-
|
| 541 |
-
with gr.TabItem("📚 Exemplos", id=1):
|
| 542 |
-
with gr.Row():
|
| 543 |
-
with gr.Column(scale=1):
|
| 544 |
-
gr.Markdown("### 🎨 Estruturas de Exemplo")
|
| 545 |
-
|
| 546 |
-
project_type = gr.Radio(
|
| 547 |
-
choices=[
|
| 548 |
-
("React App", "react"),
|
| 549 |
-
("Django Project", "django"),
|
| 550 |
-
("Vue.js App", "vue"),
|
| 551 |
-
("Node.js API", "nodejs")
|
| 552 |
-
],
|
| 553 |
-
label="Selecione o tipo de projeto",
|
| 554 |
-
value="react"
|
| 555 |
-
)
|
| 556 |
-
|
| 557 |
-
load_demo_btn = gr.Button(
|
| 558 |
-
"📖 Carregar Exemplo",
|
| 559 |
-
variant="primary"
|
| 560 |
-
)
|
| 561 |
-
|
| 562 |
-
with gr.Column(scale=2):
|
| 563 |
-
gr.Markdown("### 🏗️ Estrutura de Referência")
|
| 564 |
-
|
| 565 |
-
output_demo = gr.Textbox(
|
| 566 |
-
label="Estrutura de Exemplo",
|
| 567 |
-
lines=20,
|
| 568 |
-
show_copy_button=True,
|
| 569 |
-
elem_classes=["structure-box"]
|
| 570 |
-
)
|
| 571 |
-
|
| 572 |
-
with gr.TabItem("ℹ️ Ajuda", id=2):
|
| 573 |
-
gr.Markdown("""
|
| 574 |
-
## 🆘 Guia de Uso - Como Selecionar Pastas
|
| 575 |
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 579 |
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
minha-pasta-projetos/
|
| 589 |
-
└── 📁 meu-app-react/ ← SELECIONE ESTA PASTA!
|
| 590 |
-
├── 📁 src/
|
| 591 |
-
├── 📁 public/
|
| 592 |
-
├── 📄 package.json
|
| 593 |
-
└── 📄 README.md
|
| 594 |
-
```
|
| 595 |
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
├── 📁 src/
|
| 601 |
-
├── 📁 public/
|
| 602 |
-
├── 📄 package.json ← NÃO SELECIONE ESTE ARQUIVO!
|
| 603 |
-
└── 📄 README.md
|
| 604 |
-
```
|
| 605 |
|
| 606 |
-
|
| 607 |
-
-
|
| 608 |
-
-
|
| 609 |
-
-
|
| 610 |
-
-
|
| 611 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 612 |
|
| 613 |
-
#
|
| 614 |
-
def
|
| 615 |
-
|
| 616 |
-
return
|
| 617 |
-
|
| 618 |
-
# Quando uma pasta é selecionada OU configurações mudam
|
| 619 |
-
folder_input.change(
|
| 620 |
-
fn=analyze_project_structure,
|
| 621 |
-
inputs=[folder_input, max_depth],
|
| 622 |
-
outputs=[stats_display, output_structure, gr.File(visible=False)]
|
| 623 |
-
)
|
| 624 |
-
|
| 625 |
-
max_depth.change(
|
| 626 |
-
fn=analyze_project_structure,
|
| 627 |
-
inputs=[folder_input, max_depth],
|
| 628 |
-
outputs=[stats_display, output_structure, gr.File(visible=False)]
|
| 629 |
-
)
|
| 630 |
|
| 631 |
analyze_btn.click(
|
| 632 |
-
fn=
|
| 633 |
-
inputs=[
|
| 634 |
-
outputs=[
|
| 635 |
)
|
| 636 |
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
load_demo_btn.click(
|
| 643 |
-
fn=load_demo_structure,
|
| 644 |
-
inputs=[project_type],
|
| 645 |
-
outputs=[output_demo]
|
| 646 |
)
|
| 647 |
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
"""Exporta estrutura como arquivo"""
|
| 651 |
-
if not structure or structure.startswith("ℹ️") or structure.startswith("❌"):
|
| 652 |
-
return None
|
| 653 |
-
|
| 654 |
-
try:
|
| 655 |
-
temp_file = tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False, encoding='utf-8')
|
| 656 |
-
temp_file.write(structure)
|
| 657 |
-
temp_file.close()
|
| 658 |
-
return temp_file.name
|
| 659 |
-
except Exception as e:
|
| 660 |
-
print(f"Erro ao exportar: {e}")
|
| 661 |
-
return None
|
| 662 |
|
| 663 |
-
|
| 664 |
-
fn=export_report,
|
| 665 |
-
inputs=[output_structure],
|
| 666 |
-
outputs=gr.File(label="Download da Estrutura")
|
| 667 |
-
)
|
| 668 |
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
"ℹ️ A estrutura do projeto aparecerá aqui após a seleção...",
|
| 674 |
-
gr.File(visible=False)
|
| 675 |
-
)
|
| 676 |
|
| 677 |
-
|
| 678 |
-
fn=clear_analysis,
|
| 679 |
-
outputs=[stats_display, output_structure, gr.File(visible=False)]
|
| 680 |
-
)
|
| 681 |
|
| 682 |
-
|
| 683 |
-
def load_initial_demo():
|
| 684 |
-
return analyzer.analyze_demo_projects("react")
|
| 685 |
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
outputs=[output_demo]
|
| 689 |
-
)
|
| 690 |
-
|
| 691 |
-
return interface
|
| 692 |
-
|
| 693 |
-
# ================== Execução Principal ==================
|
| 694 |
-
|
| 695 |
-
def main():
|
| 696 |
-
"""Função principal"""
|
| 697 |
-
print("🚀 Iniciando Web Project Structure Analyzer...")
|
| 698 |
-
print("📁 Modo: Análise de Pastas Completas")
|
| 699 |
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
interface.launch(
|
| 703 |
-
server_name="0.0.0.0",
|
| 704 |
-
server_port=7860,
|
| 705 |
-
share=False,
|
| 706 |
-
show_error=True
|
| 707 |
-
)
|
| 708 |
|
| 709 |
if __name__ == "__main__":
|
| 710 |
-
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from pathlib import Path
|
| 4 |
import tempfile
|
| 5 |
+
from typing import List, Set, Dict, Tuple
|
| 6 |
|
| 7 |
class WebProjectAnalyzer:
|
| 8 |
def __init__(self):
|
|
|
|
| 13 |
'coverage', '.github', '.circleci', '.docker', 'venv',
|
| 14 |
'env', '.venv', 'virtualenv', 'bin', 'include', 'lib',
|
| 15 |
'lib64', 'site-packages', 'dist-packages', '.gitlab',
|
| 16 |
+
'.svn', '.hg', '.pytest_cache', '.mypy_cache', '__MACOSX',
|
| 17 |
+
'.next', '.nuxt', 'out', 'target', '.gradle', '.mvn',
|
| 18 |
+
'bower_components', 'jspm_packages', 'web_modules',
|
| 19 |
+
'.serverless', '.fusebox', '.dynamodb', '.tern-port',
|
| 20 |
+
'.yarn', '.pnp', 'eggs', 'wheels', 'htmlcov', '.tox',
|
| 21 |
+
'.hypothesis', '.ruff_cache', 'var', 'sdist', 'develop-eggs',
|
| 22 |
+
'.sass-cache', '.cache', 'public/packs', 'public/assets'
|
| 23 |
}
|
| 24 |
|
| 25 |
+
# Extensões relevantes para projetos web (PRINCIPAIS)
|
| 26 |
self.relevant_extensions = {
|
| 27 |
+
# Frontend
|
| 28 |
+
'.html', '.htm', '.css', '.scss', '.sass', '.less',
|
| 29 |
+
'.js', '.jsx', '.ts', '.tsx', '.vue', '.svelte',
|
| 30 |
+
# Backend
|
| 31 |
+
'.py', '.rb', '.php', '.java', '.go', '.rs',
|
| 32 |
+
# Config importantes
|
| 33 |
+
'.json', '.yml', '.yaml', '.toml', '.xml',
|
| 34 |
+
# Docs
|
| 35 |
+
'.md', '.txt',
|
| 36 |
+
# SQL
|
| 37 |
+
'.sql',
|
| 38 |
+
# Outros
|
| 39 |
+
'.env.example', '.gitignore', '.dockerignore'
|
| 40 |
}
|
| 41 |
|
| 42 |
+
# Arquivos de configuração CRÍTICOS (sempre incluir)
|
| 43 |
+
self.critical_files = {
|
| 44 |
+
'package.json', 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml',
|
| 45 |
+
'requirements.txt', 'Pipfile', 'Pipfile.lock', 'pyproject.toml',
|
| 46 |
+
'composer.json', 'composer.lock', 'Gemfile', 'Gemfile.lock',
|
| 47 |
+
'go.mod', 'go.sum', 'Cargo.toml', 'Cargo.lock',
|
| 48 |
+
'pom.xml', 'build.gradle', 'settings.gradle',
|
| 49 |
+
'CMakeLists.txt', 'Makefile', 'tsconfig.json',
|
| 50 |
+
'webpack.config.js', 'vite.config.js', 'rollup.config.js',
|
| 51 |
+
'docker-compose.yml', 'Dockerfile', '.dockerignore',
|
| 52 |
+
'.env.example', '.gitignore', '.eslintrc', '.prettierrc',
|
| 53 |
+
'README.md', 'LICENSE', 'setup.py', 'setup.cfg',
|
| 54 |
+
'manage.py', 'wsgi.py', 'asgi.py', 'app.py', 'main.py',
|
| 55 |
+
'index.html', 'index.js', 'index.ts', 'App.js', 'App.tsx',
|
| 56 |
+
'next.config.js', 'nuxt.config.js', 'vue.config.js',
|
| 57 |
+
'angular.json', 'nest-cli.json', 'vercel.json', 'netlify.toml'
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
# Padrões de nomes de arquivos a ignorar
|
| 61 |
+
self.ignored_file_patterns = {
|
| 62 |
+
'.min.js', '.min.css', '.map', '.lock', '.log',
|
| 63 |
+
'.pyc', '.pyo', '.pyd', '.so', '.dll', '.dylib',
|
| 64 |
+
'.class', '.jar', '.war', '.ear', '.zip', '.tar', '.gz',
|
| 65 |
+
'.exe', '.bin', '.dat', '.db', '.sqlite', '.sqlite3',
|
| 66 |
+
'thumbs.db', '.DS_Store', 'desktop.ini'
|
| 67 |
}
|
| 68 |
|
| 69 |
+
def should_ignore(self, name: str, path: str, is_dir: bool) -> bool:
|
| 70 |
"""Determina se um arquivo/diretório deve ser ignorado"""
|
| 71 |
# Ignora diretórios específicos
|
| 72 |
+
if is_dir and name in self.ignored_dirs:
|
| 73 |
return True
|
| 74 |
+
|
| 75 |
+
# Ignora arquivos críticos? NÃO!
|
| 76 |
+
if name in self.critical_files:
|
| 77 |
+
return False
|
| 78 |
|
| 79 |
+
# Ignora arquivos ocultos (exceto importantes)
|
| 80 |
+
if name.startswith('.') and name not in self.critical_files:
|
| 81 |
+
if not name.endswith('.example') and not name in ['.gitignore', '.dockerignore', '.env.example']:
|
|
|
|
| 82 |
return True
|
| 83 |
+
|
| 84 |
# Ignora arquivos temporários
|
| 85 |
+
if name.endswith('~') or name.startswith('~') or name.startswith('#'):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
return True
|
| 87 |
+
|
| 88 |
+
# Ignora padrões específicos
|
| 89 |
+
if any(pattern in name for pattern in self.ignored_file_patterns):
|
| 90 |
return True
|
| 91 |
+
|
| 92 |
+
# Ignora arquivos muito grandes (>10MB)
|
| 93 |
+
if not is_dir:
|
| 94 |
+
try:
|
| 95 |
+
if os.path.getsize(path) > 10 * 1024 * 1024:
|
| 96 |
+
return True
|
| 97 |
+
except:
|
| 98 |
+
pass
|
| 99 |
|
| 100 |
return False
|
| 101 |
|
| 102 |
+
def is_relevant_file(self, name: str) -> bool:
|
| 103 |
"""Determina se um arquivo é relevante para mostrar"""
|
| 104 |
+
# Arquivos críticos sempre são relevantes
|
| 105 |
+
if name in self.critical_files:
|
| 106 |
return True
|
| 107 |
+
|
| 108 |
+
# Ignora padrões indesejados
|
| 109 |
+
if any(pattern in name for pattern in self.ignored_file_patterns):
|
| 110 |
+
return False
|
| 111 |
|
| 112 |
# Verifica extensões relevantes
|
| 113 |
_, ext = os.path.splitext(name)
|
| 114 |
return ext.lower() in self.relevant_extensions
|
| 115 |
|
| 116 |
+
def get_file_icon(self, filename: str) -> str:
|
| 117 |
"""Retorna ícone apropriado para o tipo de arquivo"""
|
| 118 |
_, ext = os.path.splitext(filename)
|
| 119 |
|
| 120 |
+
# Arquivos específicos
|
| 121 |
+
if filename in ['package.json', 'package-lock.json']:
|
| 122 |
+
return '📦'
|
| 123 |
+
if filename in ['requirements.txt', 'Pipfile']:
|
| 124 |
+
return '🐍'
|
| 125 |
+
if filename in ['docker-compose.yml', 'Dockerfile']:
|
| 126 |
+
return '🐳'
|
| 127 |
+
if filename == 'README.md':
|
| 128 |
+
return '📖'
|
| 129 |
+
if filename in ['.gitignore', '.dockerignore']:
|
| 130 |
+
return '🚫'
|
| 131 |
+
if filename.startswith('.env'):
|
| 132 |
+
return '🔐'
|
| 133 |
+
|
| 134 |
+
# Por extensão
|
| 135 |
icon_map = {
|
| 136 |
'.py': '🐍', '.js': '📜', '.jsx': '⚛️', '.ts': '📘', '.tsx': '⚛️',
|
| 137 |
'.html': '🌐', '.htm': '🌐', '.css': '🎨', '.scss': '🎨', '.less': '🎨',
|
| 138 |
'.php': '🐘', '.java': '☕', '.rb': '💎', '.json': '📋', '.xml': '📄',
|
| 139 |
'.sql': '🗃️', '.md': '📖', '.txt': '📄', '.yml': '⚙️', '.yaml': '⚙️',
|
| 140 |
+
'.toml': '⚙️', '.vue': '💚', '.svelte': '🟢', '.rs': '🦀', '.go': '🐹'
|
|
|
|
| 141 |
}
|
| 142 |
|
| 143 |
return icon_map.get(ext, '📄')
|
| 144 |
|
| 145 |
+
def analyze_structure(self, root_path: str, max_depth: int = 4) -> Tuple[str, Dict, List[str]]:
|
| 146 |
"""Analisa a estrutura do projeto"""
|
| 147 |
if not root_path:
|
| 148 |
+
return "❌ Nenhum arquivo/pasta selecionado.", {"total_files": 0, "relevant_files": 0, "total_size": 0}, []
|
| 149 |
+
|
| 150 |
+
# Detecta se é arquivo ou pasta
|
| 151 |
+
if os.path.isfile(root_path):
|
| 152 |
+
# Se for arquivo, usa o diretório pai
|
| 153 |
+
root_path = os.path.dirname(root_path)
|
| 154 |
|
| 155 |
if not os.path.exists(root_path):
|
| 156 |
return "❌ Pasta não encontrada.", {"total_files": 0, "relevant_files": 0, "total_size": 0}, []
|
| 157 |
|
| 158 |
if not os.path.isdir(root_path):
|
| 159 |
+
return "❌ Caminho inválido.", {"total_files": 0, "relevant_files": 0, "total_size": 0}, []
|
| 160 |
|
| 161 |
structure_output = []
|
| 162 |
relevant_files = []
|
|
|
|
| 166 |
'total_size': 0
|
| 167 |
}
|
| 168 |
|
| 169 |
+
def analyze_directory(current_path: str, level: int = 0, prefix: str = ''):
|
| 170 |
if level > max_depth:
|
| 171 |
return
|
|
|
|
|
|
|
| 172 |
|
| 173 |
try:
|
| 174 |
items = sorted(os.listdir(current_path))
|
|
|
|
| 176 |
dirs = []
|
| 177 |
files = []
|
| 178 |
|
| 179 |
+
# Separa diretórios e arquivos
|
| 180 |
for item in items:
|
| 181 |
full_path = os.path.join(current_path, item)
|
| 182 |
+
is_dir = os.path.isdir(full_path)
|
| 183 |
|
| 184 |
+
if self.should_ignore(item, full_path, is_dir):
|
| 185 |
continue
|
| 186 |
+
|
| 187 |
+
if is_dir:
|
| 188 |
dirs.append(item)
|
| 189 |
else:
|
|
|
|
|
|
|
| 190 |
stats['total_files'] += 1
|
| 191 |
if self.is_relevant_file(item):
|
| 192 |
+
files.append(item)
|
| 193 |
stats['relevant_files'] += 1
|
| 194 |
relevant_files.append(full_path)
|
| 195 |
+
|
| 196 |
+
try:
|
| 197 |
+
stats['total_size'] += os.path.getsize(full_path)
|
| 198 |
+
except:
|
| 199 |
+
pass
|
| 200 |
|
| 201 |
+
# Renderiza arquivos primeiro
|
| 202 |
+
for i, file in enumerate(files):
|
| 203 |
+
is_last = (i == len(files) - 1) and len(dirs) == 0
|
| 204 |
+
connector = '└── ' if is_last else '├── '
|
| 205 |
+
icon = self.get_file_icon(file)
|
| 206 |
+
structure_output.append(f"{prefix}{connector}{icon} {file}")
|
| 207 |
|
| 208 |
+
# Renderiza diretórios depois
|
| 209 |
+
for i, dir_name in enumerate(dirs):
|
| 210 |
+
is_last = i == len(dirs) - 1
|
| 211 |
+
connector = '└── ' if is_last else '├── '
|
| 212 |
+
structure_output.append(f"{prefix}{connector}📁 {dir_name}/")
|
| 213 |
+
|
| 214 |
+
# Recursão
|
| 215 |
+
extension = ' ' if is_last else '│ '
|
| 216 |
full_path = os.path.join(current_path, dir_name)
|
| 217 |
+
analyze_directory(full_path, level + 1, prefix + extension)
|
|
|
|
| 218 |
|
| 219 |
except PermissionError:
|
| 220 |
+
structure_output.append(f"{prefix}🚫 [Acesso negado]")
|
| 221 |
except Exception as e:
|
| 222 |
+
structure_output.append(f"{prefix}⚠️ [Erro: {str(e)}]")
|
| 223 |
|
| 224 |
try:
|
| 225 |
+
# Nome da pasta raiz
|
| 226 |
+
project_name = os.path.basename(root_path)
|
| 227 |
+
structure_output.append(f"📁 {project_name}/")
|
| 228 |
|
| 229 |
+
analyze_directory(root_path, 0, '')
|
| 230 |
+
|
| 231 |
+
if not structure_output or len(structure_output) == 1:
|
| 232 |
return "ℹ️ Nenhum arquivo relevante encontrado na pasta selecionada.", stats, relevant_files
|
| 233 |
+
|
| 234 |
structure_text = '\n'.join(structure_output)
|
| 235 |
return structure_text, stats, relevant_files
|
| 236 |
|
| 237 |
except Exception as e:
|
| 238 |
+
return f"❌ Erro ao analisar: {str(e)}", stats, []
|
| 239 |
|
| 240 |
+
def create_structure_report(self, folder_path: str, structure: str, stats: Dict) -> str:
|
| 241 |
"""Cria relatório completo da estrutura"""
|
| 242 |
total_files = stats['total_files']
|
| 243 |
+
relevant_files = stats['relevant_files']
|
| 244 |
total_size = stats['total_size']
|
| 245 |
|
| 246 |
folder_name = os.path.basename(folder_path)
|
| 247 |
|
| 248 |
+
report = f"""# 📊 ANÁLISE DO PROJETO: `{folder_name}`
|
| 249 |
+
|
| 250 |
+
## 📍 Informações
|
| 251 |
+
|
| 252 |
+
- **Pasta Analisada**: `{folder_path}`
|
| 253 |
+
- **Data da Análise**: {gr.DateTime.now().strftime('%d/%m/%Y %H:%M:%S')}
|
|
|
|
| 254 |
|
| 255 |
+
## 📈 Estatísticas
|
| 256 |
|
| 257 |
+
| Métrica | Valor |
|
| 258 |
+
|---------|-------|
|
| 259 |
+
| 📁 Total de arquivos escaneados | {total_files} |
|
| 260 |
+
| ✅ Arquivos relevantes | {relevant_files} |
|
| 261 |
+
| 💾 Tamanho total | {total_size / 1024 / 1024:.2f} MB |
|
| 262 |
+
| 🎯 Taxa de relevância | {(relevant_files/total_files*100) if total_files > 0 else 0:.1f}% |
|
| 263 |
|
| 264 |
+
---
|
| 265 |
|
| 266 |
+
## 🌳 Estrutura do Projeto
|
| 267 |
+
|
| 268 |
+
```
|
| 269 |
{structure}
|
| 270 |
+
```
|
| 271 |
+
|
| 272 |
+
---
|
| 273 |
+
|
| 274 |
+
## 💡 Legenda
|
| 275 |
|
| 276 |
+
- 📁 Diretório
|
| 277 |
+
- 🐍 Python
|
| 278 |
+
- 📜 JavaScript
|
| 279 |
+
- ⚛️ React (JSX/TSX)
|
| 280 |
+
- 📘 TypeScript
|
| 281 |
+
- 🌐 HTML
|
| 282 |
+
- 🎨 CSS/SCSS
|
| 283 |
+
- 📦 Package Config
|
| 284 |
+
- 🐳 Docker
|
| 285 |
+
- 📖 Documentação
|
| 286 |
+
- 🚫 Git/Docker Ignore
|
| 287 |
+
- 🔐 Environment
|
| 288 |
+
|
| 289 |
+
---
|
| 290 |
+
|
| 291 |
+
**✨ Apenas arquivos estruturais e de configuração principais foram incluídos**
|
| 292 |
"""
|
| 293 |
return report
|
| 294 |
|
| 295 |
+
def process_files(self, files, max_depth: int = 4):
|
| 296 |
+
"""Processa os arquivos enviados"""
|
| 297 |
+
if not files:
|
| 298 |
+
return (
|
| 299 |
+
"**📁 Status**: Aguardando upload...",
|
| 300 |
+
"ℹ️ Faça upload de arquivos ou pasta para análise...",
|
| 301 |
+
None
|
| 302 |
+
)
|
| 303 |
|
| 304 |
try:
|
| 305 |
+
# Pega o primeiro arquivo para determinar o diretório
|
| 306 |
+
if isinstance(files, list):
|
| 307 |
+
first_file = files[0] if files else None
|
| 308 |
else:
|
| 309 |
+
first_file = files
|
| 310 |
|
| 311 |
+
if not first_file:
|
| 312 |
+
return "❌ Nenhum arquivo válido.", "", None
|
| 313 |
+
|
| 314 |
+
# Extrai o caminho e determina a pasta raiz
|
| 315 |
+
if hasattr(first_file, 'name'):
|
| 316 |
+
file_path = first_file.name
|
| 317 |
+
else:
|
| 318 |
+
file_path = str(first_file)
|
| 319 |
+
|
| 320 |
+
# Determina a pasta raiz do projeto
|
| 321 |
+
if os.path.isfile(file_path):
|
| 322 |
+
root_path = os.path.dirname(file_path)
|
| 323 |
+
else:
|
| 324 |
+
root_path = file_path
|
| 325 |
|
| 326 |
# Analisa estrutura
|
| 327 |
+
structure, stats, relevant_files = self.analyze_structure(root_path, max_depth)
|
| 328 |
|
| 329 |
# Cria relatório
|
| 330 |
+
report = self.create_structure_report(root_path, structure, stats)
|
| 331 |
|
| 332 |
+
# Salva relatório em arquivo temporário
|
| 333 |
+
temp_file = tempfile.NamedTemporaryFile(mode='w', suffix='.md', delete=False, encoding='utf-8')
|
| 334 |
+
temp_file.write(report)
|
| 335 |
+
temp_file.close()
|
| 336 |
+
|
| 337 |
+
return report, structure, temp_file.name
|
| 338 |
|
| 339 |
except Exception as e:
|
| 340 |
error_msg = f"❌ Erro ao processar: {str(e)}"
|
| 341 |
+
return error_msg, "", None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
|
|
|
|
| 343 |
|
| 344 |
def create_interface():
|
| 345 |
"""Cria a interface Gradio"""
|
|
|
|
| 347 |
analyzer = WebProjectAnalyzer()
|
| 348 |
|
| 349 |
with gr.Blocks(
|
| 350 |
+
title="🔍 Web Project Structure Analyzer",
|
| 351 |
+
theme=gr.themes.Soft(primary_hue="purple"),
|
| 352 |
+
) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
|
| 354 |
+
gr.Markdown("""
|
| 355 |
+
# 🔍 Web Project Structure Analyzer
|
| 356 |
+
|
| 357 |
+
### Analise a estrutura do seu projeto web de forma simples
|
| 358 |
+
|
| 359 |
+
**✨ Recursos:**
|
| 360 |
+
- 📤 Upload de pasta completa do projeto
|
| 361 |
+
- 🎯 Filtragem inteligente (ignora node_modules, .git, cache, etc)
|
| 362 |
+
- 📊 Estatísticas detalhadas
|
| 363 |
+
- 💾 Download do relatório em Markdown
|
| 364 |
+
- 🌳 Visualização em árvore
|
| 365 |
+
""")
|
| 366 |
+
|
| 367 |
+
with gr.Row():
|
| 368 |
+
with gr.Column(scale=1):
|
| 369 |
+
gr.Markdown("### 📤 Upload do Projeto")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
|
| 371 |
+
files_input = gr.File(
|
| 372 |
+
label="Arraste sua pasta ou clique para selecionar",
|
| 373 |
+
file_count="multiple",
|
| 374 |
+
file_types=None,
|
| 375 |
+
type="filepath",
|
| 376 |
+
height=200
|
| 377 |
+
)
|
| 378 |
+
|
| 379 |
+
max_depth = gr.Slider(
|
| 380 |
+
minimum=1,
|
| 381 |
+
maximum=6,
|
| 382 |
+
value=4,
|
| 383 |
+
step=1,
|
| 384 |
+
label="🔍 Profundidade de Análise",
|
| 385 |
+
info="Níveis de subpastas"
|
| 386 |
+
)
|
| 387 |
|
| 388 |
+
analyze_btn = gr.Button(
|
| 389 |
+
"🚀 Analisar Estrutura",
|
| 390 |
+
variant="primary",
|
| 391 |
+
size="lg"
|
| 392 |
+
)
|
| 393 |
|
| 394 |
+
gr.Markdown("""
|
| 395 |
+
### ℹ️ O que é analisado?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
|
| 397 |
+
**✅ Incluído:**
|
| 398 |
+
- Código fonte (.py, .js, .html, .css)
|
| 399 |
+
- Configs (package.json, requirements.txt)
|
| 400 |
+
- Docs (README.md, LICENSE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
|
| 402 |
+
**🚫 Ignorado:**
|
| 403 |
+
- node_modules, .git, venv
|
| 404 |
+
- Cache, logs, builds
|
| 405 |
+
- Dependências compiladas
|
| 406 |
+
- Arquivos temporários
|
| 407 |
""")
|
| 408 |
+
|
| 409 |
+
with gr.Column(scale=2):
|
| 410 |
+
gr.Markdown("### 📊 Resultado")
|
| 411 |
+
|
| 412 |
+
report_output = gr.Markdown(
|
| 413 |
+
value="**📁 Status**: Aguardando upload...",
|
| 414 |
+
label="Relatório da Análise"
|
| 415 |
+
)
|
| 416 |
+
|
| 417 |
+
structure_output = gr.Code(
|
| 418 |
+
label="🌳 Estrutura em Árvore",
|
| 419 |
+
language="text",
|
| 420 |
+
lines=20,
|
| 421 |
+
value="ℹ️ A estrutura aparecerá aqui após a análise..."
|
| 422 |
+
)
|
| 423 |
+
|
| 424 |
+
download_output = gr.File(
|
| 425 |
+
label="💾 Download do Relatório (Markdown)",
|
| 426 |
+
visible=False
|
| 427 |
+
)
|
| 428 |
|
| 429 |
+
# Eventos
|
| 430 |
+
def analyze_wrapper(files, depth):
|
| 431 |
+
report, structure, file_path = analyzer.process_files(files, depth)
|
| 432 |
+
return report, structure, gr.File(value=file_path, visible=True) if file_path else gr.File(visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
|
| 434 |
analyze_btn.click(
|
| 435 |
+
fn=analyze_wrapper,
|
| 436 |
+
inputs=[files_input, max_depth],
|
| 437 |
+
outputs=[report_output, structure_output, download_output]
|
| 438 |
)
|
| 439 |
|
| 440 |
+
files_input.change(
|
| 441 |
+
fn=analyze_wrapper,
|
| 442 |
+
inputs=[files_input, max_depth],
|
| 443 |
+
outputs=[report_output, structure_output, download_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
)
|
| 445 |
|
| 446 |
+
gr.Markdown("""
|
| 447 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
|
| 449 |
+
### 🎯 Dicas de Uso
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
|
| 451 |
+
1. **Upload**: Arraste TODA a pasta do projeto
|
| 452 |
+
2. **Análise**: Aguarde o processamento automático
|
| 453 |
+
3. **Resultado**: Copie a estrutura ou baixe o relatório
|
| 454 |
+
4. **Profundidade**: Ajuste para projetos grandes (padrão: 4 níveis)
|
|
|
|
|
|
|
|
|
|
| 455 |
|
| 456 |
+
**💡 Melhor para**: React, Vue, Django, Node.js, Next.js, Flask e outros projetos web
|
|
|
|
|
|
|
|
|
|
| 457 |
|
| 458 |
+
---
|
|
|
|
|
|
|
| 459 |
|
| 460 |
+
**Made with ❤️ using Gradio 5.49.1+**
|
| 461 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
|
| 463 |
+
return demo
|
| 464 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
|
| 466 |
if __name__ == "__main__":
|
| 467 |
+
demo = create_interface()
|
| 468 |
+
demo.launch()
|