Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
-
app.py - nanoGentzen Neurosymbolic Studio (Gradio
|
| 3 |
Coupling Gemma-2-2B generative reasoning with deterministic Gentzen Sequent Calculus (LI & LK).
|
| 4 |
"""
|
| 5 |
|
|
@@ -9,7 +9,6 @@ import time
|
|
| 9 |
from typing import Any, Dict, Generator, List, Optional, Tuple
|
| 10 |
|
| 11 |
import gradio as gr
|
| 12 |
-
import torch
|
| 13 |
from huggingface_hub import InferenceClient
|
| 14 |
from safetensors.torch import load_file
|
| 15 |
|
|
@@ -153,7 +152,7 @@ def chat_stream(
|
|
| 153 |
max_tokens: int,
|
| 154 |
max_depth: int,
|
| 155 |
) -> Generator[List[Dict[str, str]], None, None]:
|
| 156 |
-
# 1.
|
| 157 |
has_turnstile = bool(re.search(r"(\|-|⟶|⊢)", message))
|
| 158 |
if has_turnstile:
|
| 159 |
res = prove_comprehensive(message, max_depth=int(max_depth))
|
|
@@ -173,7 +172,7 @@ def chat_stream(
|
|
| 173 |
yield history
|
| 174 |
return
|
| 175 |
|
| 176 |
-
# 2. Serverless
|
| 177 |
client = InferenceClient()
|
| 178 |
api_messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 179 |
for msg in history:
|
|
@@ -243,15 +242,15 @@ custom_css = """
|
|
| 243 |
.proof-display { font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; }
|
| 244 |
"""
|
| 245 |
|
| 246 |
-
with gr.Blocks(
|
| 247 |
gr.Markdown("# 🧠 nanoGentzen Neurosymbolic Studio")
|
| 248 |
gr.Markdown(
|
| 249 |
-
"**System 1 (Neural LLM)** generates chain-of-thought traces, while **System 2 (nanoGentzen)** certifies mathematical soundness in < 25 ms
|
| 250 |
)
|
| 251 |
|
| 252 |
with gr.Tabs():
|
| 253 |
with gr.Tab("💬 Neurosymbolic Chat"):
|
| 254 |
-
chatbot = gr.Chatbot(
|
| 255 |
with gr.Row():
|
| 256 |
msg_input = gr.Textbox(
|
| 257 |
placeholder="Enter a logic problem, question, or sequent (e.g., '(P => Q), ~Q |- ~P')...",
|
|
@@ -298,7 +297,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), css=custom_css) as de
|
|
| 298 |
).then(lambda: "", None, msg_input)
|
| 299 |
|
| 300 |
with gr.Tab("🔬 Dual-Mode Logic Prover Lab"):
|
| 301 |
-
gr.Markdown("### Interactive Sequent Verification (
|
| 302 |
with gr.Row():
|
| 303 |
prover_input = gr.Textbox(
|
| 304 |
value="(P => Q), ~Q |- ~P",
|
|
@@ -310,11 +309,11 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), css=custom_css) as de
|
|
| 310 |
|
| 311 |
with gr.Row():
|
| 312 |
with gr.Column():
|
| 313 |
-
gr.Markdown("#### 🌿 Intuitionistic Logic (LI)
|
| 314 |
li_status_out = gr.Textbox(label="Status", interactive=False)
|
| 315 |
li_tree_out = gr.Code(label="Derivation Tree", language="markdown")
|
| 316 |
with gr.Column():
|
| 317 |
-
gr.Markdown("#### 🏛️ Classical Logic (LK via Glivenko)
|
| 318 |
lk_status_out = gr.Textbox(label="Status", interactive=False)
|
| 319 |
lk_tree_out = gr.Code(label="Derivation Tree", language="markdown")
|
| 320 |
|
|
@@ -325,4 +324,4 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), css=custom_css) as de
|
|
| 325 |
)
|
| 326 |
|
| 327 |
if __name__ == "__main__":
|
| 328 |
-
demo.launch()
|
|
|
|
| 1 |
"""
|
| 2 |
+
app.py - nanoGentzen Neurosymbolic Studio (Gradio 6.x Edition)
|
| 3 |
Coupling Gemma-2-2B generative reasoning with deterministic Gentzen Sequent Calculus (LI & LK).
|
| 4 |
"""
|
| 5 |
|
|
|
|
| 9 |
from typing import Any, Dict, Generator, List, Optional, Tuple
|
| 10 |
|
| 11 |
import gradio as gr
|
|
|
|
| 12 |
from huggingface_hub import InferenceClient
|
| 13 |
from safetensors.torch import load_file
|
| 14 |
|
|
|
|
| 152 |
max_tokens: int,
|
| 153 |
max_depth: int,
|
| 154 |
) -> Generator[List[Dict[str, str]], None, None]:
|
| 155 |
+
# 1. Direct formal sequent check
|
| 156 |
has_turnstile = bool(re.search(r"(\|-|⟶|⊢)", message))
|
| 157 |
if has_turnstile:
|
| 158 |
res = prove_comprehensive(message, max_depth=int(max_depth))
|
|
|
|
| 172 |
yield history
|
| 173 |
return
|
| 174 |
|
| 175 |
+
# 2. Serverless LLM Stream
|
| 176 |
client = InferenceClient()
|
| 177 |
api_messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 178 |
for msg in history:
|
|
|
|
| 242 |
.proof-display { font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; }
|
| 243 |
"""
|
| 244 |
|
| 245 |
+
with gr.Blocks() as demo:
|
| 246 |
gr.Markdown("# 🧠 nanoGentzen Neurosymbolic Studio")
|
| 247 |
gr.Markdown(
|
| 248 |
+
"**System 1 (Neural LLM)** generates chain-of-thought traces, while **System 2 (nanoGentzen)** certifies mathematical soundness in < 25 ms."
|
| 249 |
)
|
| 250 |
|
| 251 |
with gr.Tabs():
|
| 252 |
with gr.Tab("💬 Neurosymbolic Chat"):
|
| 253 |
+
chatbot = gr.Chatbot(height=520)
|
| 254 |
with gr.Row():
|
| 255 |
msg_input = gr.Textbox(
|
| 256 |
placeholder="Enter a logic problem, question, or sequent (e.g., '(P => Q), ~Q |- ~P')...",
|
|
|
|
| 297 |
).then(lambda: "", None, msg_input)
|
| 298 |
|
| 299 |
with gr.Tab("🔬 Dual-Mode Logic Prover Lab"):
|
| 300 |
+
gr.Markdown("### Interactive Sequent Verification (LI vs LK)")
|
| 301 |
with gr.Row():
|
| 302 |
prover_input = gr.Textbox(
|
| 303 |
value="(P => Q), ~Q |- ~P",
|
|
|
|
| 309 |
|
| 310 |
with gr.Row():
|
| 311 |
with gr.Column():
|
| 312 |
+
gr.Markdown("#### 🌿 Intuitionistic Logic (LI)")
|
| 313 |
li_status_out = gr.Textbox(label="Status", interactive=False)
|
| 314 |
li_tree_out = gr.Code(label="Derivation Tree", language="markdown")
|
| 315 |
with gr.Column():
|
| 316 |
+
gr.Markdown("#### 🏛️ Classical Logic (LK via Glivenko)")
|
| 317 |
lk_status_out = gr.Textbox(label="Status", interactive=False)
|
| 318 |
lk_tree_out = gr.Code(label="Derivation Tree", language="markdown")
|
| 319 |
|
|
|
|
| 324 |
)
|
| 325 |
|
| 326 |
if __name__ == "__main__":
|
| 327 |
+
demo.launch(theme=gr.themes.Soft(primary_hue="indigo"), css=custom_css)
|