andrefbfreitas commited on
Commit
1f8e6d5
·
verified ·
1 Parent(s): a35e9d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -27,7 +27,7 @@ from OCC.Core.StlAPI import StlAPI_Writer
27
  os.environ['PYVISTA_OFF_SCREEN'] = 'true'
28
  os.environ['VTK_GRAPHICS_BACKEND'] = 'OSMesa'
29
 
30
- st.set_page_config(page_title="CastingSim V31", layout="wide")
31
 
32
  st.markdown("""
33
  <style>
@@ -70,7 +70,7 @@ if 'vel_vaz' not in st.session_state: st.session_state.vel_vaz = 1.0
70
 
71
  if 'b64_termico' not in st.session_state: st.session_state.b64_termico = ""
72
  if 'b64_rechupe_x10' not in st.session_state: st.session_state.b64_rechupe_x10 = ""
73
- if 'frames_glb' not in st.session_state: st.session_state.frames_glb = [] # NOVO: Cache de animação 4D
74
  if 't_sol_minutos' not in st.session_state: st.session_state.t_sol_minutos = 0
75
  if 't_sol_segundos' not in st.session_state: st.session_state.t_sol_segundos = 0
76
  if 'relatorio_ia' not in st.session_state: st.session_state.relatorio_ia = ""
@@ -82,7 +82,7 @@ def compilar_pdf():
82
  pdf = FPDF()
83
  pdf.add_page()
84
  pdf.set_font("Arial", 'B', 16)
85
- pdf.cell(0, 10, "LAUDO DE ENGENHARIA - CASTINGSIM V31", 0, 1, 'C')
86
  pdf.ln(5)
87
 
88
  pdf.set_font("Arial", 'B', 12)
@@ -206,7 +206,7 @@ if st.session_state.step in [1, 2, 3, 4, 4.5, 5]:
206
  st.caption("**ETAPA EXTRA: RENDERIZAÇÃO DE VÍDEO**")
207
 
208
  if st.session_state.step not in [3.5, 4.5]:
209
- st.title("🛡️ CastingSim V31: WebGL Cinematic Flow")
210
  st.markdown("---")
211
 
212
  # ==========================================
@@ -497,7 +497,7 @@ elif st.session_state.step == 4:
497
  st.download_button(
498
  label="📄 Baixar Laudo (.PDF)",
499
  data=st.session_state.relatorio_pdf,
500
- file_name="Laudo_CastingSim_V31.pdf",
501
  mime="application/pdf",
502
  type="primary",
503
  use_container_width=True
@@ -513,7 +513,7 @@ elif st.session_state.step == 4:
513
  # ==========================================
514
  elif st.session_state.step == 4.5:
515
  st.title("🎬 Extração Cinemática (Motor WebGL)")
516
- st.info("Bypass ativado: O servidor não vai mais desenhar pixels. Ele está exportando as coordenadas tridimensionais do fluido para a sua GPU processar.")
517
  prog_video = st.progress(0, text="Iniciando cálculos vetoriais...")
518
 
519
  try:
@@ -523,8 +523,14 @@ elif st.session_state.step == 4.5:
523
  mesh_video.rotate_y(st.session_state.rot_y, inplace=True)
524
  mesh_video.rotate_z(st.session_state.rot_z, inplace=True)
525
 
526
- # Guardamos a "carcaça" do molde (transparente) para juntar com o metal em todos os frames
 
527
  mesh_molde_wire = mesh_video.copy()
 
 
 
 
 
528
  mesh_molde_wire.points /= 1000.0
529
 
530
  p_riser = np.array([st.session_state.off_x, st.session_state.off_y, st.session_state.off_z])
@@ -532,8 +538,8 @@ elif st.session_state.step == 4.5:
532
  max_fluxo_vid = np.max(dist_video)
533
  mesh_video['Dist_Massalote'] = dist_video
534
 
535
- st.session_state.frames_glb = [] # Limpa a memória de vídeos anteriores
536
- passos = 10 # 10 frames cravados (Suficiente para WebGL fluido sem estourar o limite de rede Base64)
537
 
538
  for i in range(1, passos + 1):
539
  limite = (max_fluxo_vid / passos) * i
@@ -541,7 +547,6 @@ elif st.session_state.step == 4.5:
541
 
542
  frame_mesh = mesh_video.threshold([0, limite], scalars='Dist_Massalote')
543
 
544
- # Não renderiza na tela, apenas agrupa as geometrias para exportação
545
  plotter_export = pv.Plotter(off_screen=True)
546
  plotter_export.add_mesh(mesh_molde_wire, color='white', opacity=0.10, style='wireframe')
547
 
@@ -556,7 +561,6 @@ elif st.session_state.step == 4.5:
556
 
557
  plotter_export.close()
558
 
559
- # Força o Streamlit a atualizar a barra
560
  time.sleep(0.05)
561
  prog_video.progress(10 + int((i/passos)*85), text=f"Forjando Geometria 4D: Frame {i}/{passos} (Extração Pura)...")
562
 
@@ -589,10 +593,8 @@ elif st.session_state.step == 5:
589
  st.write(f"Velocidade de Vazamento: **{st.session_state.vel_vaz} m/s** | Modo: Interativo 3D")
590
 
591
  if len(st.session_state.frames_glb) > 0:
592
- # Pega a matriz de frames em Python e injeta direto no Javascript do frontend
593
  frames_js_array = ",\n".join([f'"{b64}"' for b64 in st.session_state.frames_glb])
594
 
595
- # O Motor Javascript que fará a mágica de stop-motion usando o hardware do usuário
596
  html_player = f"""
597
  <html>
598
  <head>
@@ -632,10 +634,9 @@ elif st.session_state.step == 5:
632
  clearInterval(timer);
633
  isPlaying = false;
634
  }}
635
- }}, 200); // 200ms = 5 frames por segundo (ritmo ideal para ver a física fluir)
636
  }}
637
 
638
- // Dispara o vídeo automaticamente assim que a página carregar
639
  setTimeout(play, 1000);
640
  </script>
641
  </body>
 
27
  os.environ['PYVISTA_OFF_SCREEN'] = 'true'
28
  os.environ['VTK_GRAPHICS_BACKEND'] = 'OSMesa'
29
 
30
+ st.set_page_config(page_title="CastingSim V32", layout="wide")
31
 
32
  st.markdown("""
33
  <style>
 
70
 
71
  if 'b64_termico' not in st.session_state: st.session_state.b64_termico = ""
72
  if 'b64_rechupe_x10' not in st.session_state: st.session_state.b64_rechupe_x10 = ""
73
+ if 'frames_glb' not in st.session_state: st.session_state.frames_glb = []
74
  if 't_sol_minutos' not in st.session_state: st.session_state.t_sol_minutos = 0
75
  if 't_sol_segundos' not in st.session_state: st.session_state.t_sol_segundos = 0
76
  if 'relatorio_ia' not in st.session_state: st.session_state.relatorio_ia = ""
 
82
  pdf = FPDF()
83
  pdf.add_page()
84
  pdf.set_font("Arial", 'B', 16)
85
+ pdf.cell(0, 10, "LAUDO DE ENGENHARIA - CASTINGSIM V32", 0, 1, 'C')
86
  pdf.ln(5)
87
 
88
  pdf.set_font("Arial", 'B', 12)
 
206
  st.caption("**ETAPA EXTRA: RENDERIZAÇÃO DE VÍDEO**")
207
 
208
  if st.session_state.step not in [3.5, 4.5]:
209
+ st.title("🛡️ CastingSim V32: Pipeline Expandida e Casca Otimizada")
210
  st.markdown("---")
211
 
212
  # ==========================================
 
497
  st.download_button(
498
  label="📄 Baixar Laudo (.PDF)",
499
  data=st.session_state.relatorio_pdf,
500
+ file_name="Laudo_CastingSim_V32.pdf",
501
  mime="application/pdf",
502
  type="primary",
503
  use_container_width=True
 
513
  # ==========================================
514
  elif st.session_state.step == 4.5:
515
  st.title("🎬 Extração Cinemática (Motor WebGL)")
516
+ st.info("Bypass ativado: Extraindo fluido em Alta Resolução. Casca de vidro otimizada.")
517
  prog_video = st.progress(0, text="Iniciando cálculos vetoriais...")
518
 
519
  try:
 
523
  mesh_video.rotate_y(st.session_state.rot_y, inplace=True)
524
  mesh_video.rotate_z(st.session_state.rot_z, inplace=True)
525
 
526
+ # O PULO DO GATO V32: A casca de referência (molde) é esmagada em 90%.
527
+ # O fluxo de alumínio continuará em 100% High-Res.
528
  mesh_molde_wire = mesh_video.copy()
529
+ try:
530
+ if mesh_molde_wire.n_faces > 5000:
531
+ mesh_molde_wire = mesh_molde_wire.decimate(0.9)
532
+ except:
533
+ pass
534
  mesh_molde_wire.points /= 1000.0
535
 
536
  p_riser = np.array([st.session_state.off_x, st.session_state.off_y, st.session_state.off_z])
 
538
  max_fluxo_vid = np.max(dist_video)
539
  mesh_video['Dist_Massalote'] = dist_video
540
 
541
+ st.session_state.frames_glb = []
542
+ passos = 10
543
 
544
  for i in range(1, passos + 1):
545
  limite = (max_fluxo_vid / passos) * i
 
547
 
548
  frame_mesh = mesh_video.threshold([0, limite], scalars='Dist_Massalote')
549
 
 
550
  plotter_export = pv.Plotter(off_screen=True)
551
  plotter_export.add_mesh(mesh_molde_wire, color='white', opacity=0.10, style='wireframe')
552
 
 
561
 
562
  plotter_export.close()
563
 
 
564
  time.sleep(0.05)
565
  prog_video.progress(10 + int((i/passos)*85), text=f"Forjando Geometria 4D: Frame {i}/{passos} (Extração Pura)...")
566
 
 
593
  st.write(f"Velocidade de Vazamento: **{st.session_state.vel_vaz} m/s** | Modo: Interativo 3D")
594
 
595
  if len(st.session_state.frames_glb) > 0:
 
596
  frames_js_array = ",\n".join([f'"{b64}"' for b64 in st.session_state.frames_glb])
597
 
 
598
  html_player = f"""
599
  <html>
600
  <head>
 
634
  clearInterval(timer);
635
  isPlaying = false;
636
  }}
637
+ }}, 200);
638
  }}
639
 
 
640
  setTimeout(play, 1000);
641
  </script>
642
  </body>