Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -86,16 +86,22 @@ class WebProjectAnalyzer:
|
|
| 86 |
|
| 87 |
def analyze_structure_from_path(self, root_path, max_depth=4):
|
| 88 |
"""Analisa estrutura a partir de um caminho local"""
|
|
|
|
|
|
|
|
|
|
| 89 |
if not os.path.exists(root_path):
|
| 90 |
-
return "❌
|
| 91 |
|
| 92 |
if not os.path.isdir(root_path):
|
| 93 |
-
return "❌ O caminho
|
| 94 |
-
|
| 95 |
-
structure = self._analyze_directory(root_path, max_depth)
|
| 96 |
-
stats = self._calculate_stats(root_path)
|
| 97 |
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
def _analyze_directory(self, root_dir, max_depth, level=0):
|
| 101 |
"""Analisa recursivamente um diretório"""
|
|
@@ -177,21 +183,26 @@ class WebProjectAnalyzer:
|
|
| 177 |
'total_size': total_size
|
| 178 |
}
|
| 179 |
|
| 180 |
-
def _format_output(self, stats, structure):
|
| 181 |
"""Formata a saída com estatísticas e estrutura"""
|
| 182 |
total_files = stats['total_files']
|
| 183 |
relevant_files = stats['relevant_files']
|
| 184 |
total_size = stats['total_size']
|
| 185 |
|
|
|
|
|
|
|
| 186 |
stats_report = f"""
|
| 187 |
-
📊 **
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
• 📁 Total de arquivos: {total_files}
|
| 190 |
• 📄 Arquivos relevantes: {relevant_files}
|
| 191 |
• 💾 Tamanho aproximado: {total_size / 1024 / 1024:.2f} MB
|
| 192 |
-
•
|
| 193 |
|
| 194 |
-
🔍 **ESTRUTURA DO PROJETO**
|
| 195 |
"""
|
| 196 |
return stats_report + "\n" + structure
|
| 197 |
|
|
@@ -332,6 +343,38 @@ meu-app-flask/
|
|
| 332 |
📄 run.py
|
| 333 |
📄 requirements.txt
|
| 334 |
📄 config.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
📄 README.md
|
| 336 |
"""
|
| 337 |
}
|
|
@@ -343,7 +386,7 @@ meu-app-flask/
|
|
| 343 |
{demos[project_type]}
|
| 344 |
|
| 345 |
💡 **Dica:** Esta é uma estrutura de exemplo. Para analisar seu próprio projeto,
|
| 346 |
-
use
|
| 347 |
"""
|
| 348 |
else:
|
| 349 |
return "❌ Tipo de projeto não encontrado."
|
|
@@ -370,29 +413,12 @@ def create_interface():
|
|
| 370 |
color: white;
|
| 371 |
margin-bottom: 25px;
|
| 372 |
}
|
| 373 |
-
.
|
| 374 |
-
|
| 375 |
-
gap: 10px;
|
| 376 |
-
margin-bottom: 20px;
|
| 377 |
-
}
|
| 378 |
-
.tab-button {
|
| 379 |
-
flex: 1;
|
| 380 |
padding: 15px;
|
| 381 |
-
text-align: center;
|
| 382 |
-
background: #f8f9fa;
|
| 383 |
-
border: 2px solid #dee2e6;
|
| 384 |
border-radius: 10px;
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
}
|
| 388 |
-
.tab-button:hover {
|
| 389 |
-
background: #e9ecef;
|
| 390 |
-
border-color: #007bff;
|
| 391 |
-
}
|
| 392 |
-
.tab-button.active {
|
| 393 |
-
background: #007bff;
|
| 394 |
-
color: white;
|
| 395 |
-
border-color: #007bff;
|
| 396 |
}
|
| 397 |
.structure-box {
|
| 398 |
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
|
@@ -403,12 +429,36 @@ def create_interface():
|
|
| 403 |
border-radius: 10px;
|
| 404 |
border: 1px solid #dee2e6;
|
| 405 |
}
|
| 406 |
-
.
|
| 407 |
-
background: #
|
| 408 |
-
|
|
|
|
| 409 |
border-radius: 10px;
|
| 410 |
margin: 15px 0;
|
| 411 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
"""
|
| 413 |
) as interface:
|
| 414 |
|
|
@@ -416,7 +466,7 @@ def create_interface():
|
|
| 416 |
"""
|
| 417 |
<div class="header">
|
| 418 |
<h1>🔍 Web Project Structure Analyzer</h1>
|
| 419 |
-
<p>
|
| 420 |
</div>
|
| 421 |
"""
|
| 422 |
)
|
|
@@ -426,55 +476,89 @@ def create_interface():
|
|
| 426 |
with gr.TabItem("🎯 Análise Local", id=0):
|
| 427 |
with gr.Row():
|
| 428 |
with gr.Column(scale=1):
|
| 429 |
-
gr.Markdown("### 📁
|
| 430 |
-
|
| 431 |
-
path_input = gr.Textbox(
|
| 432 |
-
label="Caminho do Projeto",
|
| 433 |
-
placeholder="Ex: /home/usuario/meu-projeto ou C:\\Users\\Usuario\\meu-projeto",
|
| 434 |
-
lines=2,
|
| 435 |
-
info="Digite o caminho completo para o diretório do projeto"
|
| 436 |
-
)
|
| 437 |
-
|
| 438 |
-
max_depth = gr.Slider(
|
| 439 |
-
minimum=1,
|
| 440 |
-
maximum=6,
|
| 441 |
-
value=4,
|
| 442 |
-
step=1,
|
| 443 |
-
label="Profundidade Máxima",
|
| 444 |
-
info="Níveis de subpastas a serem analisados"
|
| 445 |
-
)
|
| 446 |
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
|
| 453 |
-
gr.
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
|
| 465 |
with gr.Column(scale=2):
|
| 466 |
gr.Markdown("### 📊 Resultado da Análise")
|
| 467 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
output_local = gr.Textbox(
|
| 469 |
label="Estrutura do Projeto",
|
| 470 |
-
lines=
|
| 471 |
show_copy_button=True,
|
| 472 |
elem_classes=["structure-box"]
|
| 473 |
)
|
| 474 |
|
|
|
|
| 475 |
with gr.Row():
|
| 476 |
-
export_btn = gr.Button(
|
| 477 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
|
| 479 |
with gr.TabItem("📚 Exemplos", id=1):
|
| 480 |
with gr.Row():
|
|
@@ -486,7 +570,8 @@ def create_interface():
|
|
| 486 |
("React App", "react"),
|
| 487 |
("Django Project", "django"),
|
| 488 |
("Vue.js App", "vue"),
|
| 489 |
-
("Flask App", "flask")
|
|
|
|
| 490 |
],
|
| 491 |
label="Selecione o tipo de projeto",
|
| 492 |
value="react"
|
|
@@ -496,6 +581,13 @@ def create_interface():
|
|
| 496 |
"📖 Carregar Exemplo",
|
| 497 |
variant="primary"
|
| 498 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
|
| 500 |
with gr.Column(scale=2):
|
| 501 |
gr.Markdown("### 🏗️ Estrutura de Referência")
|
|
@@ -509,78 +601,101 @@ def create_interface():
|
|
| 509 |
|
| 510 |
with gr.TabItem("ℹ️ Ajuda", id=2):
|
| 511 |
gr.Markdown("""
|
| 512 |
-
## 🆘 Guia de Uso
|
| 513 |
|
| 514 |
### 🎯 **Análise Local**
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
|
|
|
|
|
|
| 518 |
|
| 519 |
-
|
| 520 |
-
-
|
| 521 |
-
-
|
| 522 |
-
-
|
|
|
|
| 523 |
|
| 524 |
-
###
|
| 525 |
-
|
| 526 |
-
-
|
| 527 |
-
-
|
| 528 |
-
-
|
|
|
|
|
|
|
| 529 |
|
| 530 |
-
###
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
|
|
|
| 535 |
|
| 536 |
-
###
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
|
| 542 |
-
###
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
""")
|
| 548 |
|
| 549 |
# Manipuladores de eventos para Análise Local
|
| 550 |
-
def
|
| 551 |
-
"""Analisa
|
| 552 |
-
if not
|
| 553 |
-
return "
|
| 554 |
|
| 555 |
try:
|
| 556 |
-
# No
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
**
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
|
|
|
|
|
|
| 577 |
except Exception as e:
|
| 578 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 579 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 580 |
analyze_btn.click(
|
| 581 |
-
fn=
|
| 582 |
-
inputs=[
|
| 583 |
-
outputs=[output_local]
|
| 584 |
)
|
| 585 |
|
| 586 |
# Manipuladores para Exemplos
|
|
@@ -597,7 +712,7 @@ def create_interface():
|
|
| 597 |
# Exportação
|
| 598 |
def export_structure(structure):
|
| 599 |
"""Exporta estrutura como arquivo"""
|
| 600 |
-
if not structure or structure.startswith("❌"):
|
| 601 |
return None
|
| 602 |
|
| 603 |
try:
|
|
@@ -616,12 +731,12 @@ def create_interface():
|
|
| 616 |
)
|
| 617 |
|
| 618 |
# Limpar
|
| 619 |
-
def
|
| 620 |
-
return ""
|
| 621 |
|
| 622 |
clear_btn.click(
|
| 623 |
-
fn=
|
| 624 |
-
outputs=[output_local]
|
| 625 |
)
|
| 626 |
|
| 627 |
# Carregar exemplo inicial
|
|
@@ -640,7 +755,7 @@ def create_interface():
|
|
| 640 |
def main():
|
| 641 |
"""Função principal"""
|
| 642 |
print("🚀 Iniciando Web Project Structure Analyzer...")
|
| 643 |
-
print("📍 Modo:
|
| 644 |
|
| 645 |
# Cria e inicia a interface
|
| 646 |
interface = create_interface()
|
|
|
|
| 86 |
|
| 87 |
def analyze_structure_from_path(self, root_path, max_depth=4):
|
| 88 |
"""Analisa estrutura a partir de um caminho local"""
|
| 89 |
+
if not root_path:
|
| 90 |
+
return "❌ Nenhuma pasta selecionada. Por favor, selecione uma pasta para analisar."
|
| 91 |
+
|
| 92 |
if not os.path.exists(root_path):
|
| 93 |
+
return "❌ Pasta não encontrada. Verifique se o diretório ainda existe."
|
| 94 |
|
| 95 |
if not os.path.isdir(root_path):
|
| 96 |
+
return "❌ O caminho selecionado não é uma pasta."
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
try:
|
| 99 |
+
structure = self._analyze_directory(root_path, max_depth)
|
| 100 |
+
stats = self._calculate_stats(root_path)
|
| 101 |
+
|
| 102 |
+
return self._format_output(root_path, stats, structure)
|
| 103 |
+
except Exception as e:
|
| 104 |
+
return f"❌ Erro ao analisar a pasta: {str(e)}"
|
| 105 |
|
| 106 |
def _analyze_directory(self, root_dir, max_depth, level=0):
|
| 107 |
"""Analisa recursivamente um diretório"""
|
|
|
|
| 183 |
'total_size': total_size
|
| 184 |
}
|
| 185 |
|
| 186 |
+
def _format_output(self, folder_path, stats, structure):
|
| 187 |
"""Formata a saída com estatísticas e estrutura"""
|
| 188 |
total_files = stats['total_files']
|
| 189 |
relevant_files = stats['relevant_files']
|
| 190 |
total_size = stats['total_size']
|
| 191 |
|
| 192 |
+
folder_name = os.path.basename(folder_path)
|
| 193 |
+
|
| 194 |
stats_report = f"""
|
| 195 |
+
📊 **ANÁLISE DA PASTA**: `{folder_name}`
|
| 196 |
+
📍 **Localização**: {folder_path}
|
| 197 |
+
|
| 198 |
+
📈 **ESTATÍSTICAS**:
|
| 199 |
|
| 200 |
• 📁 Total de arquivos: {total_files}
|
| 201 |
• 📄 Arquivos relevantes: {relevant_files}
|
| 202 |
• 💾 Tamanho aproximado: {total_size / 1024 / 1024:.2f} MB
|
| 203 |
+
• 🎯 Taxa de relevância: {(relevant_files/total_files*100) if total_files > 0 else 0:.1f}%
|
| 204 |
|
| 205 |
+
🔍 **ESTRUTURA DO PROJETO**:
|
| 206 |
"""
|
| 207 |
return stats_report + "\n" + structure
|
| 208 |
|
|
|
|
| 343 |
📄 run.py
|
| 344 |
📄 requirements.txt
|
| 345 |
📄 config.py
|
| 346 |
+
📄 README.md
|
| 347 |
+
""",
|
| 348 |
+
|
| 349 |
+
"nodejs": """
|
| 350 |
+
meu-app-nodejs/
|
| 351 |
+
📁 src/
|
| 352 |
+
📁 controllers/
|
| 353 |
+
📄 userController.js
|
| 354 |
+
📄 productController.js
|
| 355 |
+
📁 models/
|
| 356 |
+
📄 User.js
|
| 357 |
+
📄 Product.js
|
| 358 |
+
📁 routes/
|
| 359 |
+
📄 auth.js
|
| 360 |
+
📄 users.js
|
| 361 |
+
📄 products.js
|
| 362 |
+
📁 middleware/
|
| 363 |
+
📄 auth.js
|
| 364 |
+
📄 validation.js
|
| 365 |
+
📁 utils/
|
| 366 |
+
📄 database.js
|
| 367 |
+
📄 logger.js
|
| 368 |
+
📄 app.js
|
| 369 |
+
📄 server.js
|
| 370 |
+
📁 config/
|
| 371 |
+
📄 database.js
|
| 372 |
+
📄 environment.js
|
| 373 |
+
📁 tests/
|
| 374 |
+
📄 user.test.js
|
| 375 |
+
📄 product.test.js
|
| 376 |
+
📄 package.json
|
| 377 |
+
📄 .env.example
|
| 378 |
📄 README.md
|
| 379 |
"""
|
| 380 |
}
|
|
|
|
| 386 |
{demos[project_type]}
|
| 387 |
|
| 388 |
💡 **Dica:** Esta é uma estrutura de exemplo. Para analisar seu próprio projeto,
|
| 389 |
+
use o botão "Selecionar Pasta" na aba "Análise Local".
|
| 390 |
"""
|
| 391 |
else:
|
| 392 |
return "❌ Tipo de projeto não encontrado."
|
|
|
|
| 413 |
color: white;
|
| 414 |
margin-bottom: 25px;
|
| 415 |
}
|
| 416 |
+
.folder-info {
|
| 417 |
+
background: #e7f3ff;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
padding: 15px;
|
|
|
|
|
|
|
|
|
|
| 419 |
border-radius: 10px;
|
| 420 |
+
margin: 10px 0;
|
| 421 |
+
border-left: 4px solid #007bff;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
}
|
| 423 |
.structure-box {
|
| 424 |
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
|
|
|
| 429 |
border-radius: 10px;
|
| 430 |
border: 1px solid #dee2e6;
|
| 431 |
}
|
| 432 |
+
.warning-box {
|
| 433 |
+
background: #fff3cd;
|
| 434 |
+
border: 1px solid #ffeaa7;
|
| 435 |
+
padding: 15px;
|
| 436 |
border-radius: 10px;
|
| 437 |
margin: 15px 0;
|
| 438 |
}
|
| 439 |
+
.stats-grid {
|
| 440 |
+
display: grid;
|
| 441 |
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
| 442 |
+
gap: 15px;
|
| 443 |
+
margin: 20px 0;
|
| 444 |
+
}
|
| 445 |
+
.stat-card {
|
| 446 |
+
background: white;
|
| 447 |
+
padding: 15px;
|
| 448 |
+
border-radius: 8px;
|
| 449 |
+
border: 1px solid #dee2e6;
|
| 450 |
+
text-align: center;
|
| 451 |
+
}
|
| 452 |
+
.stat-value {
|
| 453 |
+
font-size: 24px;
|
| 454 |
+
font-weight: bold;
|
| 455 |
+
color: #007bff;
|
| 456 |
+
}
|
| 457 |
+
.stat-label {
|
| 458 |
+
font-size: 12px;
|
| 459 |
+
color: #6c757d;
|
| 460 |
+
margin-top: 5px;
|
| 461 |
+
}
|
| 462 |
"""
|
| 463 |
) as interface:
|
| 464 |
|
|
|
|
| 466 |
"""
|
| 467 |
<div class="header">
|
| 468 |
<h1>🔍 Web Project Structure Analyzer</h1>
|
| 469 |
+
<p>Selecione uma pasta e visualize a estrutura do projeto de forma inteligente</p>
|
| 470 |
</div>
|
| 471 |
"""
|
| 472 |
)
|
|
|
|
| 476 |
with gr.TabItem("🎯 Análise Local", id=0):
|
| 477 |
with gr.Row():
|
| 478 |
with gr.Column(scale=1):
|
| 479 |
+
gr.Markdown("### 📁 Selecionar Pasta")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
|
| 481 |
+
with gr.Group():
|
| 482 |
+
folder_input = gr.File(
|
| 483 |
+
label="Selecione a pasta do projeto",
|
| 484 |
+
file_count="directory",
|
| 485 |
+
type="filepath",
|
| 486 |
+
height=100
|
| 487 |
+
)
|
| 488 |
+
|
| 489 |
+
gr.Markdown("""
|
| 490 |
+
**📌 Como usar:**
|
| 491 |
+
1. Clique no botão acima
|
| 492 |
+
2. Selecione a pasta do seu projeto
|
| 493 |
+
3. A análise começará automaticamente
|
| 494 |
+
""")
|
| 495 |
|
| 496 |
+
with gr.Group():
|
| 497 |
+
gr.Markdown("### ⚙️ Configurações")
|
| 498 |
+
|
| 499 |
+
max_depth = gr.Slider(
|
| 500 |
+
minimum=1,
|
| 501 |
+
maximum=6,
|
| 502 |
+
value=4,
|
| 503 |
+
step=1,
|
| 504 |
+
label="Profundidade Máxima",
|
| 505 |
+
info="Níveis de subpastas a serem analisados"
|
| 506 |
+
)
|
| 507 |
+
|
| 508 |
+
with gr.Row():
|
| 509 |
+
analyze_btn = gr.Button(
|
| 510 |
+
"🔍 Analisar Novamente",
|
| 511 |
+
variant="primary"
|
| 512 |
+
)
|
| 513 |
+
clear_btn = gr.Button(
|
| 514 |
+
"🗑️ Limpar",
|
| 515 |
+
variant="secondary"
|
| 516 |
+
)
|
| 517 |
|
| 518 |
+
with gr.Accordion("💡 Informações", open=True):
|
| 519 |
+
gr.Markdown("""
|
| 520 |
+
**🎯 O que é mostrado:**
|
| 521 |
+
- Pastas e arquivos de código
|
| 522 |
+
- Arquivos de configuração importantes
|
| 523 |
+
- Documentação e README
|
| 524 |
+
- Estrutura organizada com ícones
|
| 525 |
+
|
| 526 |
+
**🚫 O que é ignorado:**
|
| 527 |
+
- node_modules, .git, venv
|
| 528 |
+
- Arquivos de cache e temporários
|
| 529 |
+
- Dependências e pacotes
|
| 530 |
+
- Logs e builds
|
| 531 |
+
""")
|
| 532 |
|
| 533 |
with gr.Column(scale=2):
|
| 534 |
gr.Markdown("### 📊 Resultado da Análise")
|
| 535 |
|
| 536 |
+
# Informações da pasta selecionada
|
| 537 |
+
folder_info = gr.Markdown(
|
| 538 |
+
label="Informações da Pasta",
|
| 539 |
+
elem_classes=["folder-info"]
|
| 540 |
+
)
|
| 541 |
+
|
| 542 |
+
# Resultado principal
|
| 543 |
output_local = gr.Textbox(
|
| 544 |
label="Estrutura do Projeto",
|
| 545 |
+
lines=16,
|
| 546 |
show_copy_button=True,
|
| 547 |
elem_classes=["structure-box"]
|
| 548 |
)
|
| 549 |
|
| 550 |
+
# Botões de ação
|
| 551 |
with gr.Row():
|
| 552 |
+
export_btn = gr.Button(
|
| 553 |
+
"💾 Exportar como Texto",
|
| 554 |
+
variant="secondary",
|
| 555 |
+
size="sm"
|
| 556 |
+
)
|
| 557 |
+
gr.HTML("""
|
| 558 |
+
<div style="text-align: center; color: #666; font-size: 12px; margin-top: 10px;">
|
| 559 |
+
🎯 A análise é feita localmente - seus arquivos não são enviados para a internet
|
| 560 |
+
</div>
|
| 561 |
+
""")
|
| 562 |
|
| 563 |
with gr.TabItem("📚 Exemplos", id=1):
|
| 564 |
with gr.Row():
|
|
|
|
| 570 |
("React App", "react"),
|
| 571 |
("Django Project", "django"),
|
| 572 |
("Vue.js App", "vue"),
|
| 573 |
+
("Flask App", "flask"),
|
| 574 |
+
("Node.js API", "nodejs")
|
| 575 |
],
|
| 576 |
label="Selecione o tipo de projeto",
|
| 577 |
value="react"
|
|
|
|
| 581 |
"📖 Carregar Exemplo",
|
| 582 |
variant="primary"
|
| 583 |
)
|
| 584 |
+
|
| 585 |
+
gr.Markdown("""
|
| 586 |
+
**🎯 Objetivo:**
|
| 587 |
+
- Estudar boas práticas de organização
|
| 588 |
+
- Comparar com seus projetos
|
| 589 |
+
- Aprender padrões de estrutura
|
| 590 |
+
""")
|
| 591 |
|
| 592 |
with gr.Column(scale=2):
|
| 593 |
gr.Markdown("### 🏗️ Estrutura de Referência")
|
|
|
|
| 601 |
|
| 602 |
with gr.TabItem("ℹ️ Ajuda", id=2):
|
| 603 |
gr.Markdown("""
|
| 604 |
+
## 🆘 Guia de Uso Completo
|
| 605 |
|
| 606 |
### 🎯 **Análise Local**
|
| 607 |
+
**Como funciona:**
|
| 608 |
+
1. Clique em "Selecionar Pasta"
|
| 609 |
+
2. Escolha a pasta do seu projeto no explorador de arquivos
|
| 610 |
+
3. A análise é feita automaticamente
|
| 611 |
+
4. Visualize a estrutura organizada
|
| 612 |
|
| 613 |
+
**Vantagens:**
|
| 614 |
+
- ✅ Não requer upload de arquivos
|
| 615 |
+
- ✅ Processamento 100% local
|
| 616 |
+
- ✅ Rápido e eficiente
|
| 617 |
+
- ✅ Mantém seus dados privados
|
| 618 |
|
| 619 |
+
### 📚 **Exemplos**
|
| 620 |
+
**Projetos disponíveis:**
|
| 621 |
+
- ⚛️ React.js
|
| 622 |
+
- 🐍 Django
|
| 623 |
+
- 💚 Vue.js
|
| 624 |
+
- 🌶️ Flask
|
| 625 |
+
- 🟢 Node.js
|
| 626 |
|
| 627 |
+
### 🔍 **Tecnologias Reconhecidas**
|
| 628 |
+
**Frontend:** HTML, CSS, JavaScript, TypeScript, Vue, React, Angular
|
| 629 |
+
**Backend:** Python, PHP, Java, Node.js, Go, Rust
|
| 630 |
+
**Mobile:** React Native, Flutter
|
| 631 |
+
**Config:** JSON, YAML, TOML, XML
|
| 632 |
+
**Docs:** Markdown, Texto
|
| 633 |
|
| 634 |
+
### 🚫 **Arquivos Ignorados**
|
| 635 |
+
- Desenvolvimento: `node_modules`, `venv`, `.git`
|
| 636 |
+
- Cache: `__pycache__`, `.vscode`, `.idea`
|
| 637 |
+
- Build: `dist`, `build`, `.next`
|
| 638 |
+
- Sistema: `.DS_Store`, `Thumbs.db`
|
| 639 |
|
| 640 |
+
### 💡 **Dicas Práticas**
|
| 641 |
+
1. Use profundidade 3-4 para projetos médios
|
| 642 |
+
2. Exporte resultados para documentação
|
| 643 |
+
3. Compare com exemplos para melhorar organização
|
| 644 |
+
4. Use em code reviews
|
| 645 |
""")
|
| 646 |
|
| 647 |
# Manipuladores de eventos para Análise Local
|
| 648 |
+
def analyze_selected_folder(files, max_depth_value):
|
| 649 |
+
"""Analisa pasta selecionada"""
|
| 650 |
+
if not files:
|
| 651 |
+
return "ℹ️ Selecione uma pasta para analisar...", "**📁 Nenhuma pasta selecionada**"
|
| 652 |
|
| 653 |
try:
|
| 654 |
+
# No Gradio, quando file_count="directory", files é uma lista com um caminho
|
| 655 |
+
folder_path = files[0] if isinstance(files, list) else files
|
| 656 |
+
|
| 657 |
+
# Atualiza informações da pasta
|
| 658 |
+
folder_name = os.path.basename(folder_path)
|
| 659 |
+
folder_info_text = f"""
|
| 660 |
+
**📂 Pasta Selecionada:** `{folder_name}`
|
| 661 |
+
**📍 Localização:** `{folder_path}`
|
| 662 |
+
**🕒 Analisando...**
|
| 663 |
+
"""
|
| 664 |
+
|
| 665 |
+
# Faz a análise
|
| 666 |
+
result = analyzer.analyze_structure_from_path(folder_path, max_depth_value)
|
| 667 |
+
|
| 668 |
+
# Atualiza informações finais
|
| 669 |
+
final_folder_info = f"""
|
| 670 |
+
**📂 Pasta Selecionada:** `{folder_name}`
|
| 671 |
+
**📍 Localização:** `{folder_path}`
|
| 672 |
+
**✅ Análise Concluída!**
|
| 673 |
+
"""
|
| 674 |
+
|
| 675 |
+
return result, final_folder_info
|
| 676 |
+
|
| 677 |
except Exception as e:
|
| 678 |
+
error_msg = f"❌ Erro ao processar a pasta: {str(e)}"
|
| 679 |
+
return error_msg, "**❌ Erro na seleção**"
|
| 680 |
+
|
| 681 |
+
# Quando uma pasta é selecionada OU quando o slider muda, analisa automaticamente
|
| 682 |
+
folder_input.change(
|
| 683 |
+
fn=analyze_selected_folder,
|
| 684 |
+
inputs=[folder_input, max_depth],
|
| 685 |
+
outputs=[output_local, folder_info]
|
| 686 |
+
)
|
| 687 |
|
| 688 |
+
max_depth.change(
|
| 689 |
+
fn=analyze_selected_folder,
|
| 690 |
+
inputs=[folder_input, max_depth],
|
| 691 |
+
outputs=[output_local, folder_info]
|
| 692 |
+
)
|
| 693 |
+
|
| 694 |
+
# Botão Analisar Novamente
|
| 695 |
analyze_btn.click(
|
| 696 |
+
fn=analyze_selected_folder,
|
| 697 |
+
inputs=[folder_input, max_depth],
|
| 698 |
+
outputs=[output_local, folder_info]
|
| 699 |
)
|
| 700 |
|
| 701 |
# Manipuladores para Exemplos
|
|
|
|
| 712 |
# Exportação
|
| 713 |
def export_structure(structure):
|
| 714 |
"""Exporta estrutura como arquivo"""
|
| 715 |
+
if not structure or structure.startswith("❌") or structure.startswith("ℹ️"):
|
| 716 |
return None
|
| 717 |
|
| 718 |
try:
|
|
|
|
| 731 |
)
|
| 732 |
|
| 733 |
# Limpar
|
| 734 |
+
def clear_analysis():
|
| 735 |
+
return "ℹ️ Selecione uma pasta para analisar...", "**📁 Nenhuma pasta selecionada**"
|
| 736 |
|
| 737 |
clear_btn.click(
|
| 738 |
+
fn=clear_analysis,
|
| 739 |
+
outputs=[output_local, folder_info]
|
| 740 |
)
|
| 741 |
|
| 742 |
# Carregar exemplo inicial
|
|
|
|
| 755 |
def main():
|
| 756 |
"""Função principal"""
|
| 757 |
print("🚀 Iniciando Web Project Structure Analyzer...")
|
| 758 |
+
print("📍 Modo: Seleção de Pasta com Botão")
|
| 759 |
|
| 760 |
# Cria e inicia a interface
|
| 761 |
interface = create_interface()
|