Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -111,7 +111,7 @@ correction_projector.eval()
|
|
| 111 |
# ==============================================================================
|
| 112 |
# 4. Lógica de Inferência
|
| 113 |
# ==============================================================================
|
| 114 |
-
def predict(contexto, frase_mask):
|
| 115 |
if "[MASK]" not in frase_mask:
|
| 116 |
return "⚠️ Erro: A frase precisa conter o token [MASK]."
|
| 117 |
|
|
@@ -150,7 +150,8 @@ def predict(contexto, frase_mask):
|
|
| 150 |
# c) Passar pelo Vórtice (O Cérebro Caótico)
|
| 151 |
# O método forward retorna: evolved, loss, metrics, delta_inter
|
| 152 |
# Precisamos adicionar dimensão de batch (unsqueeze)
|
| 153 |
-
|
|
|
|
| 154 |
|
| 155 |
# d) Projetar correção de volta para dimensão do BERT
|
| 156 |
correction = correction_projector(delta).unsqueeze(1) # [1, 1, hidden_size]
|
|
@@ -176,28 +177,28 @@ def predict(contexto, frase_mask):
|
|
| 176 |
token = tokenizer.decode([idx]).strip()
|
| 177 |
res_betina.append(f"**{token}** ({score:.2%})")
|
| 178 |
|
| 179 |
-
# Formatar saída HTML
|
| 180 |
html_output = f"""
|
| 181 |
-
<div style="display: flex; gap: 20px; flex-wrap: wrap;">
|
| 182 |
-
<div style="flex: 1; min-width: 300px; background-color: #
|
| 183 |
-
<h3 style="color: #
|
| 184 |
-
<p style="font-size: 0.
|
| 185 |
<ol>
|
| 186 |
-
{''.join([f'<li>{item}</li>' for item in res_base])}
|
| 187 |
</ol>
|
| 188 |
</div>
|
| 189 |
-
<div style="flex: 1; min-width: 300px; background-color: #
|
| 190 |
-
<h3 style="color: #
|
| 191 |
-
<p style="font-size: 0.
|
| 192 |
-
<ol>
|
| 193 |
-
{''.join([f'<li>{item}</li>' for item in res_betina])}
|
| 194 |
</ol>
|
| 195 |
</div>
|
| 196 |
</div>
|
| 197 |
<br>
|
| 198 |
<details>
|
| 199 |
-
<summary style="cursor: pointer; color: #
|
| 200 |
-
<pre style="font-size: 0.8em; background: #
|
| 201 |
</details>
|
| 202 |
"""
|
| 203 |
return html_output
|
|
@@ -206,48 +207,59 @@ def predict(contexto, frase_mask):
|
|
| 206 |
# 5. Interface Gradio
|
| 207 |
# ==============================================================================
|
| 208 |
custom_css = """
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
"""
|
| 211 |
|
| 212 |
-
with gr.Blocks(title="Betina 2.0 -
|
| 213 |
gr.Markdown("""
|
| 214 |
-
# 🌀
|
| 215 |
-
|
| 216 |
-
Esta interface demonstra o poder do **Vórtice Betina**, uma arquitetura híbrida que usa sistemas dinâmicos caóticos
|
| 217 |
-
(Atrator de Lorenz, Rotação de Matrizes) para corrigir alucinações em modelos de linguagem.
|
| 218 |
|
| 219 |
-
|
| 220 |
-
|
| 221 |
""")
|
| 222 |
|
| 223 |
with gr.Row():
|
| 224 |
with gr.Column(scale=1):
|
| 225 |
txt_contexto = gr.Textbox(
|
| 226 |
-
label="1.
|
| 227 |
-
placeholder="Ex:
|
| 228 |
lines=3
|
| 229 |
)
|
| 230 |
txt_mask = gr.Textbox(
|
| 231 |
-
label="2.
|
| 232 |
-
placeholder="Ex:
|
| 233 |
lines=2
|
| 234 |
)
|
| 235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
with gr.Column(scale=1):
|
| 238 |
out_result = gr.HTML(label="Resultado Comparativo")
|
| 239 |
|
| 240 |
-
gr.Markdown("###
|
| 241 |
gr.Examples(
|
| 242 |
examples=[
|
| 243 |
-
["
|
| 244 |
-
["
|
| 245 |
-
["
|
| 246 |
],
|
| 247 |
-
inputs=[txt_contexto, txt_mask]
|
| 248 |
)
|
| 249 |
|
| 250 |
-
btn_run.click(fn=predict, inputs=[txt_contexto, txt_mask], outputs=out_result)
|
|
|
|
| 251 |
|
| 252 |
if __name__ == "__main__":
|
| 253 |
demo.launch()
|
|
|
|
| 111 |
# ==============================================================================
|
| 112 |
# 4. Lógica de Inferência
|
| 113 |
# ==============================================================================
|
| 114 |
+
def predict(contexto, frase_mask, chaos_factor):
|
| 115 |
if "[MASK]" not in frase_mask:
|
| 116 |
return "⚠️ Erro: A frase precisa conter o token [MASK]."
|
| 117 |
|
|
|
|
| 150 |
# c) Passar pelo Vórtice (O Cérebro Caótico)
|
| 151 |
# O método forward retorna: evolved, loss, metrics, delta_inter
|
| 152 |
# Precisamos adicionar dimensão de batch (unsqueeze)
|
| 153 |
+
# AGORA COM FATOR CAOS!
|
| 154 |
+
_, _, metrics, delta = vortex(proj.unsqueeze(0), chaos_factor=chaos_factor)
|
| 155 |
|
| 156 |
# d) Projetar correção de volta para dimensão do BERT
|
| 157 |
correction = correction_projector(delta).unsqueeze(1) # [1, 1, hidden_size]
|
|
|
|
| 177 |
token = tokenizer.decode([idx]).strip()
|
| 178 |
res_betina.append(f"**{token}** ({score:.2%})")
|
| 179 |
|
| 180 |
+
# Formatar saída HTML (Estilo Cyberpunk)
|
| 181 |
html_output = f"""
|
| 182 |
+
<div style="display: flex; gap: 20px; flex-wrap: wrap; font-family: 'Courier New', monospace;">
|
| 183 |
+
<div style="flex: 1; min-width: 300px; background-color: #1a1a1a; padding: 15px; border-radius: 10px; border: 1px solid #444; color: #ccc;">
|
| 184 |
+
<h3 style="color: #888; margin-top: 0; border-bottom: 1px solid #444; padding-bottom: 5px;">🧠 BERT (Legado)</h3>
|
| 185 |
+
<p style="font-size: 0.8em; color: #666;"><i>Memória Estática</i></p>
|
| 186 |
<ol>
|
| 187 |
+
{''.join([f'<li style="margin-bottom: 5px;">{item}</li>' for item in res_base])}
|
| 188 |
</ol>
|
| 189 |
</div>
|
| 190 |
+
<div style="flex: 1; min-width: 300px; background-color: #0d0d15; padding: 15px; border-radius: 10px; border: 2px solid #00ff9d; box-shadow: 0 0 15px rgba(0, 255, 157, 0.2);">
|
| 191 |
+
<h3 style="color: #00ff9d; margin-top: 0; border-bottom: 1px solid #00ff9d; padding-bottom: 5px;">🌀 VÓRTICE ATIVO</h3>
|
| 192 |
+
<p style="font-size: 0.8em; color: #00cc7d;"><i>Correção Dinâmica (Caos: {chaos_factor}x)</i></p>
|
| 193 |
+
<ol style="color: #fff;">
|
| 194 |
+
{''.join([f'<li style="margin-bottom: 5px; text-shadow: 0 0 5px #00ff9d;">{item}</li>' for item in res_betina])}
|
| 195 |
</ol>
|
| 196 |
</div>
|
| 197 |
</div>
|
| 198 |
<br>
|
| 199 |
<details>
|
| 200 |
+
<summary style="cursor: pointer; color: #00ff9d; font-family: monospace;">📊 TELEMETRIA DO VÓRTICE</summary>
|
| 201 |
+
<pre style="font-size: 0.8em; background: #000; color: #0f0; padding: 10px; border-radius: 5px; overflow-x: auto; border: 1px solid #003300;">{str(metrics)}</pre>
|
| 202 |
</details>
|
| 203 |
"""
|
| 204 |
return html_output
|
|
|
|
| 207 |
# 5. Interface Gradio
|
| 208 |
# ==============================================================================
|
| 209 |
custom_css = """
|
| 210 |
+
body {background-color: #000000; color: #e0e0e0;}
|
| 211 |
+
.gradio-container {background-color: #0a0a0a !important; border: 1px solid #333;}
|
| 212 |
+
h1 {color: #00ff9d !important; font-family: 'Courier New', monospace; text-shadow: 0 0 10px #00ff9d;}
|
| 213 |
+
label {color: #00ff9d !important;}
|
| 214 |
+
input, textarea {background-color: #111 !important; color: #fff !important; border: 1px solid #333 !important;}
|
| 215 |
+
button.primary {background: linear-gradient(45deg, #004d00, #00ff9d) !important; border: none !important; color: #000 !important; font-weight: bold !important;}
|
| 216 |
"""
|
| 217 |
|
| 218 |
+
with gr.Blocks(title="Betina 2.0 - Protocolo Impossível", css=custom_css) as demo:
|
| 219 |
gr.Markdown("""
|
| 220 |
+
# 🌀 BETINA 2.0: PROTOCOLO IMPOSSÍVEL
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
+
Sistema de correção neural baseado em **Dinâmica de Vórtice**.
|
| 223 |
+
Aumente o **Fator Caos** para forçar a lógica sobre a estatística.
|
| 224 |
""")
|
| 225 |
|
| 226 |
with gr.Row():
|
| 227 |
with gr.Column(scale=1):
|
| 228 |
txt_contexto = gr.Textbox(
|
| 229 |
+
label="1. CONTEXTO (A Verdade Absoluta)",
|
| 230 |
+
placeholder="Ex: A felicidade é medida em quilos. Se estou feliz, estou...",
|
| 231 |
lines=3
|
| 232 |
)
|
| 233 |
txt_mask = gr.Textbox(
|
| 234 |
+
label="2. CONSULTA (Use [MASK])",
|
| 235 |
+
placeholder="Ex: Estou muito feliz, logo estou [MASK].",
|
| 236 |
lines=2
|
| 237 |
)
|
| 238 |
+
slider_chaos = gr.Slider(
|
| 239 |
+
minimum=1.0,
|
| 240 |
+
maximum=50.0,
|
| 241 |
+
value=1.0,
|
| 242 |
+
step=0.5,
|
| 243 |
+
label="🔥 FATOR CAOS (Overdrive)",
|
| 244 |
+
info="1.0 = Padrão. Aumente para forçar correções impossíveis."
|
| 245 |
+
)
|
| 246 |
+
btn_run = gr.Button("🌀 INICIAR VÓRTICE", variant="primary")
|
| 247 |
|
| 248 |
with gr.Column(scale=1):
|
| 249 |
out_result = gr.HTML(label="Resultado Comparativo")
|
| 250 |
|
| 251 |
+
gr.Markdown("### 🧪 Testes de Paradoxo")
|
| 252 |
gr.Examples(
|
| 253 |
examples=[
|
| 254 |
+
["A felicidade é medida em quilos. Se estou feliz, estou...", "Estou muito feliz, logo estou [MASK].", 10.0],
|
| 255 |
+
["Neste mundo, o gelo é quente e o fogo é frio.", "Toquei no fogo e senti [MASK].", 15.0],
|
| 256 |
+
["O ciclo da vida é reverso: morremos, vivemos e nascemos.", "Depois de viver muito, eu vou [MASK].", 20.0]
|
| 257 |
],
|
| 258 |
+
inputs=[txt_contexto, txt_mask, slider_chaos]
|
| 259 |
)
|
| 260 |
|
| 261 |
+
btn_run.click(fn=predict, inputs=[txt_contexto, txt_mask, slider_chaos], outputs=out_result)
|
| 262 |
+
|
| 263 |
|
| 264 |
if __name__ == "__main__":
|
| 265 |
demo.launch()
|