Spaces:
Running on Zero
Running on Zero
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -81,8 +81,12 @@ def ensure_mathlib_import(code: str) -> str:
|
|
| 81 |
return f"import Mathlib\n\n{code.lstrip()}"
|
| 82 |
|
| 83 |
|
| 84 |
-
def split_stream(text: str) -> tuple[str, str]:
|
| 85 |
"""Split a partial generation into (reasoning, answer-so-far)."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
close = list(re.finditer(r"</think>", text, flags=re.I))
|
| 87 |
if close:
|
| 88 |
reasoning = text[: close[-1].start()]
|
|
@@ -199,13 +203,14 @@ def formalize(
|
|
| 199 |
now = time.perf_counter()
|
| 200 |
if now - last_push > 0.25:
|
| 201 |
last_push = now
|
| 202 |
-
reasoning, answer = split_stream(full)
|
| 203 |
-
|
|
|
|
| 204 |
thread.join()
|
| 205 |
|
| 206 |
elapsed = time.perf_counter() - start
|
| 207 |
n_tokens = len(tokenizer(full, add_special_tokens=False).input_ids)
|
| 208 |
-
reasoning, _ = split_stream(full)
|
| 209 |
code = ensure_mathlib_import(extract_lean_code_from_inference(full))
|
| 210 |
if not code.strip():
|
| 211 |
code = (
|
|
|
|
| 81 |
return f"import Mathlib\n\n{code.lstrip()}"
|
| 82 |
|
| 83 |
|
| 84 |
+
def split_stream(text: str, thinking: bool = True) -> tuple[str, str]:
|
| 85 |
"""Split a partial generation into (reasoning, answer-so-far)."""
|
| 86 |
+
if not thinking:
|
| 87 |
+
# `enable_thinking=False` puts the empty think block in the *prompt*,
|
| 88 |
+
# so the generation is the answer with no `</think>` marker.
|
| 89 |
+
return "", text
|
| 90 |
close = list(re.finditer(r"</think>", text, flags=re.I))
|
| 91 |
if close:
|
| 92 |
reasoning = text[: close[-1].start()]
|
|
|
|
| 203 |
now = time.perf_counter()
|
| 204 |
if now - last_push > 0.25:
|
| 205 |
last_push = now
|
| 206 |
+
reasoning, answer = split_stream(full, thinking)
|
| 207 |
+
placeholder = "Thinking…" if thinking else "(thinking disabled)"
|
| 208 |
+
yield partial_lean(answer), reasoning or placeholder, used_seed
|
| 209 |
thread.join()
|
| 210 |
|
| 211 |
elapsed = time.perf_counter() - start
|
| 212 |
n_tokens = len(tokenizer(full, add_special_tokens=False).input_ids)
|
| 213 |
+
reasoning, _ = split_stream(full, thinking)
|
| 214 |
code = ensure_mathlib_import(extract_lean_code_from_inference(full))
|
| 215 |
if not code.strip():
|
| 216 |
code = (
|