victorafarias commited on
Commit
f3597fc
·
1 Parent(s): f0b6306

Versão Estável 13082025

Browse files
Files changed (3) hide show
  1. app.py +29 -1
  2. static/style.css +13 -0
  3. templates/index.html +43 -0
app.py CHANGED
@@ -296,7 +296,20 @@ def process():
296
 
297
  claude_atomic_llm = claude_llm.bind(max_tokens=60000)
298
  #models = {'grok': grok_llm, 'sonnet': claude_atomic_llm, 'gemini': gemini_llm, 'openai': openai_llm}
299
- models = {'sonnet': claude_atomic_llm, 'gemini': gemini_llm, 'openai': openai_llm}
 
 
 
 
 
 
 
 
 
 
 
 
 
300
 
301
  # Substituir os placeholders no template
302
  updated_prompt_template = PROMPT_ATOMICO_INICIAL.replace(
@@ -555,6 +568,19 @@ def merge():
555
  yield f"data: {json_data}\n\n"
556
  return
557
 
 
 
 
 
 
 
 
 
 
 
 
 
 
558
  output_parser = StrOutputParser()
559
 
560
  # Atualizar o template de merge com os parâmetros de tamanho padrão
@@ -579,6 +605,8 @@ def merge():
579
  claude_with_max_tokens = claude_llm.bind(max_tokens=64000)
580
  chain_merge = prompt_merge | claude_with_max_tokens | output_parser
581
 
 
 
582
  json_data = safe_json_dumps({'progress': 50, 'message': 'Enviando textos para o Claude Sonnet para consolidação...'})
583
  yield f"data: {json_data}\n\n"
584
  log_print("=== INVOCANDO CLAUDE SONNET PARA MERGE ===")
 
296
 
297
  claude_atomic_llm = claude_llm.bind(max_tokens=60000)
298
  #models = {'grok': grok_llm, 'sonnet': claude_atomic_llm, 'gemini': gemini_llm, 'openai': openai_llm}
299
+ # Melhoria 05/08/2025 - Multi-modelo
300
+ models = {}
301
+ if form_data.get('modelo-openai') == 'on':
302
+ models['openai'] = openai_llm
303
+ if form_data.get('modelo-sonnet') == 'on':
304
+ models['sonnet'] = claude_atomic_llm
305
+ if form_data.get('modelo-gemini') == 'on':
306
+ models['gemini'] = gemini_llm
307
+
308
+ # Verificação se pelo menos um modelo foi selecionado
309
+ if not models:
310
+ json_data = safe_json_dumps({'error': 'Você deve selecionar pelo menos um modelo para processamento.'})
311
+ yield f"data: {json_data}\n\n"
312
+ return
313
 
314
  # Substituir os placeholders no template
315
  updated_prompt_template = PROMPT_ATOMICO_INICIAL.replace(
 
568
  yield f"data: {json_data}\n\n"
569
  return
570
 
571
+ # Monta lista só com os textos que vieram no payload
572
+ available = []
573
+ for campo in ('openai_text', 'sonnet_text', 'gemini_text'):
574
+ txt = data.get(campo)
575
+ if txt and txt.strip():
576
+ available.append(txt)
577
+ if len(available) < 2:
578
+ json_data = safe_json_dumps({
579
+ 'error': 'Para processar o merge, deve haver pelo menos dois textos gerados.'
580
+ })
581
+ yield f"data: {json_data}\n\n"
582
+ return
583
+
584
  output_parser = StrOutputParser()
585
 
586
  # Atualizar o template de merge com os parâmetros de tamanho padrão
 
605
  claude_with_max_tokens = claude_llm.bind(max_tokens=64000)
606
  chain_merge = prompt_merge | claude_with_max_tokens | output_parser
607
 
608
+
609
+
610
  json_data = safe_json_dumps({'progress': 50, 'message': 'Enviando textos para o Claude Sonnet para consolidação...'})
611
  yield f"data: {json_data}\n\n"
612
  log_print("=== INVOCANDO CLAUDE SONNET PARA MERGE ===")
static/style.css CHANGED
@@ -432,4 +432,17 @@ textarea.drag-over {
432
  .text-contexto_usuario {
433
  color: #000;
434
  font-size: 14px;
 
 
 
 
 
 
 
 
 
 
 
 
 
435
  }
 
432
  .text-contexto_usuario {
433
  color: #000;
434
  font-size: 14px;
435
+ }
436
+
437
+ /* Melhoria 05/08/2025 - Multi-modelo */
438
+ #modelo-container {
439
+ margin-top: 15px;
440
+ padding: 10px;
441
+ border: 1px solid #e0e0e0;
442
+ border-radius: 5px;
443
+ background-color: #f9f9f9;
444
+ }
445
+
446
+ #modelo-container label {
447
+ margin-right: 10px;
448
  }
templates/index.html CHANGED
@@ -511,6 +511,19 @@
511
  </div>
512
  </div>
513
 
 
 
 
 
 
 
 
 
 
 
 
 
 
514
  <button type="submit">Processar com IA</button>
515
  </form>
516
  </div>
@@ -579,6 +592,9 @@ Use o botão `Converter para MD` para ver a mágica.</textarea>
579
  <script>
580
  // --- Variáveis Globais ---
581
  const processingModeSwitch = document.getElementById('processing-mode-switch');
 
 
 
582
  const modeSwitch = document.getElementById('mode-switch');
583
  const realContainer = document.getElementById('real-form-container');
584
  const mockContainer = document.getElementById('mock-form-container');
@@ -610,8 +626,14 @@ Use o botão `Converter para MD` para ver a mágica.</textarea>
610
  mockContainer.style.display = this.checked ? 'block' : 'none';
611
  });
612
 
 
613
  processingModeSwitch.addEventListener('change', function() {
614
  const isAtomic = this.checked;
 
 
 
 
 
615
  document.getElementById('flow-description').textContent = isAtomic ?
616
  "OPEN AI | Claude Sonnet | Gemini (Paralelo)" :
617
  "OPEN AI ➔ Claude Sonnet ➔ Gemini";
@@ -700,6 +722,7 @@ Use o botão `Converter para MD` para ver a mágica.</textarea>
700
  document.getElementById('request-form-mock').addEventListener('submit', handleFormSubmit);
701
 
702
  async function handleFormSubmit(event) {
 
703
  event.preventDefault();
704
  debugLog("=== FORM SUBMIT INICIADO ===");
705
  currentProcessingType = 'main';
@@ -732,6 +755,16 @@ Use o botão `Converter para MD` para ver a mágica.</textarea>
732
  // Adicionar parâmetros de tamanho
733
  formData.append('min_chars', document.getElementById('min_chars').value);
734
  formData.append('max_chars', document.getElementById('max_chars').value);
 
 
 
 
 
 
 
 
 
 
735
 
736
  if (modeSwitch.checked) {
737
  formData.append('mode', 'test');
@@ -815,6 +848,16 @@ Use o botão `Converter para MD` para ver a mágica.</textarea>
815
  mergeBtn.addEventListener('click', async function() {
816
  debugLog("=== MERGE BUTTON CLICADO ===");
817
  currentProcessingType = 'merge';
 
 
 
 
 
 
 
 
 
 
818
 
819
  loaderMessage.textContent = 'Processando o merge dos textos...';
820
  progressBar.style.width = '0%';
 
511
  </div>
512
  </div>
513
 
514
+ <!-- Melhoria 05/08/2025 - Multi-modelo -->
515
+ <div id="modelo-container" style="display:none;">
516
+ <label>Escolha os modelos:</label>
517
+ <div>
518
+ <input type="checkbox" id="modelo-openai" name="modelo-openai" checked>
519
+ <label for="modelo-openai">OpenAI</label>
520
+ <input type="checkbox" id="modelo-sonnet" name="modelo-sonnet" checked>
521
+ <label for="modelo-sonnet">Sonnet</label>
522
+ <input type="checkbox" id="modelo-gemini" name="modelo-gemini" checked>
523
+ <label for="modelo-gemini">Gemini</label>
524
+ </div>
525
+ </div>
526
+
527
  <button type="submit">Processar com IA</button>
528
  </form>
529
  </div>
 
592
  <script>
593
  // --- Variáveis Globais ---
594
  const processingModeSwitch = document.getElementById('processing-mode-switch');
595
+ // Melhoria 05/08/2025 - Multi-modelo
596
+ const modeloContainer = document.getElementById('modelo-container');
597
+ modeloContainer.style.display = this.checked ? 'block' : 'none';
598
  const modeSwitch = document.getElementById('mode-switch');
599
  const realContainer = document.getElementById('real-form-container');
600
  const mockContainer = document.getElementById('mock-form-container');
 
626
  mockContainer.style.display = this.checked ? 'block' : 'none';
627
  });
628
 
629
+ // Melhoria 05/08/2025 - Multi-modelo
630
  processingModeSwitch.addEventListener('change', function() {
631
  const isAtomic = this.checked;
632
+
633
+ // Melhoria 05/08/2025 - Multi-modelo (Corrigido)
634
+ const modeloContainer = document.getElementById('modelo-container');
635
+ modeloContainer.style.display = isAtomic ? 'block' : 'none';
636
+
637
  document.getElementById('flow-description').textContent = isAtomic ?
638
  "OPEN AI | Claude Sonnet | Gemini (Paralelo)" :
639
  "OPEN AI ➔ Claude Sonnet ➔ Gemini";
 
722
  document.getElementById('request-form-mock').addEventListener('submit', handleFormSubmit);
723
 
724
  async function handleFormSubmit(event) {
725
+ console.clear();
726
  event.preventDefault();
727
  debugLog("=== FORM SUBMIT INICIADO ===");
728
  currentProcessingType = 'main';
 
755
  // Adicionar parâmetros de tamanho
756
  formData.append('min_chars', document.getElementById('min_chars').value);
757
  formData.append('max_chars', document.getElementById('max_chars').value);
758
+
759
+ // Melhoria 05/08/2025 - Multi-modelo: envia os check-boxes ao servidor
760
+ if (processingModeSwitch.checked) {
761
+ ['openai','sonnet','gemini'].forEach(m => {
762
+ const id = `modelo-${m}`;
763
+ if (document.getElementById(id).checked) {
764
+ formData.append(id, 'on');
765
+ }
766
+ });
767
+ }
768
 
769
  if (modeSwitch.checked) {
770
  formData.append('mode', 'test');
 
848
  mergeBtn.addEventListener('click', async function() {
849
  debugLog("=== MERGE BUTTON CLICADO ===");
850
  currentProcessingType = 'merge';
851
+
852
+ // Melhoria 05/08/2025 - validação antes de chamar o servidor
853
+ const filled = ['openai-output','sonnet-output','gemini-output']
854
+ .map(id => rawTexts[id])
855
+ .filter(text => text && text.trim().length > 0)
856
+ .length;
857
+ if (filled < 2) {
858
+ showError('Para processar o merge, deve haver pelo menos dois textos gerados.');
859
+ return;
860
+ }
861
 
862
  loaderMessage.textContent = 'Processando o merge dos textos...';
863
  progressBar.style.width = '0%';