Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -28,36 +28,33 @@ def format_prompt(formal_statement, informal_prefix=""):
|
|
28 |
def extract_code(response):
|
29 |
"""Extract code between lean4 code blocks and the model's output"""
|
30 |
try:
|
31 |
-
#
|
32 |
-
|
33 |
-
if
|
34 |
-
model_output = output_match.group(0)
|
35 |
-
else:
|
36 |
-
model_output = ""
|
37 |
-
|
38 |
-
# Extract the initial code setup
|
39 |
-
setup_match = re.search(r'```lean4\n(.*?)============================', response, re.DOTALL)
|
40 |
-
if setup_match:
|
41 |
-
setup_code = setup_match.group(1)
|
42 |
-
else:
|
43 |
return "None"
|
44 |
-
|
45 |
-
# Extract the goal
|
46 |
-
goal_match = re.search(r'============================\n\s*(.*?)(?:theorem|$)', response, re.DOTALL)
|
47 |
-
if goal_match:
|
48 |
-
goal = goal_match.group(1).strip()
|
49 |
-
else:
|
50 |
-
goal = ""
|
51 |
-
|
52 |
-
# Combine all parts
|
53 |
-
full_code = (
|
54 |
-
f"{setup_code.strip()}\n"
|
55 |
-
f"============================\n"
|
56 |
-
f"{goal}\n\n"
|
57 |
-
f"{model_output.strip()}"
|
58 |
-
)
|
59 |
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
except:
|
62 |
return "None"
|
63 |
|
@@ -146,7 +143,7 @@ def main():
|
|
146 |
title="# 🙋🏻♂️Welcome to🌟Tonic's🔮Goedel Prover📉",
|
147 |
description="""You can build with this endpoint using🔮Goedel-Prover-SFT📉 available here : [Goedel-LM/Goedel-Prover-SFT](https://huggingface.co/Goedel-LM/Goedel-Prover-SFT). We're using 🤖[introspector/unimath](https://huggingface.co/datasets/introspector/unimath) for cool examples, check it out below ! The demo is still a work in progress and we're looking forward to build downstream tasks that showcase outstanding mathematical reasoning. Have any ideas ? join us below !
|
148 |
You can also use 🔮Goedel Prover📉 by cloning this space. Simply click here: <a style="display:inline-block" href="https://huggingface.co/spaces/Tonic/Math?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></h3>
|
149 |
-
Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's 🛠️community 👻 [
|
150 |
""",
|
151 |
fn=solve_math_problem,
|
152 |
outputs=[
|
@@ -156,7 +153,7 @@ Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder
|
|
156 |
inputs=[
|
157 |
gr.Textbox(label="🤔Enter your Lean4 formal statement", lines=7),
|
158 |
gr.Textbox(value=additional_info_prompt, label="🪜Optional informal prefix"),
|
159 |
-
gr.Slider(minimum=150, maximum=
|
160 |
],
|
161 |
examples=examples
|
162 |
)
|
|
|
28 |
def extract_code(response):
|
29 |
"""Extract code between lean4 code blocks and the model's output"""
|
30 |
try:
|
31 |
+
# Find all content between ```lean4 and ``` tags
|
32 |
+
matches = re.findall(r'```lean4(.*?)```', response, re.DOTALL)
|
33 |
+
if not matches:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
return "None"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
# Get the last match which should contain the complete code including model output
|
37 |
+
full_content = matches[-1].strip()
|
38 |
+
|
39 |
+
# Clean up any duplicate headers or content
|
40 |
+
# Split the content into lines
|
41 |
+
lines = full_content.split('\n')
|
42 |
+
cleaned_lines = []
|
43 |
+
seen_headers = set()
|
44 |
+
|
45 |
+
for line in lines:
|
46 |
+
# Skip empty lines at the start
|
47 |
+
if not cleaned_lines and not line.strip():
|
48 |
+
continue
|
49 |
+
# Skip duplicate headers
|
50 |
+
if "import Mathlib" in line or "import Aesop" in line or "set_option" in line:
|
51 |
+
if line in seen_headers:
|
52 |
+
continue
|
53 |
+
seen_headers.add(line)
|
54 |
+
cleaned_lines.append(line)
|
55 |
+
|
56 |
+
# Join the lines back together
|
57 |
+
return '\n'.join(cleaned_lines)
|
58 |
except:
|
59 |
return "None"
|
60 |
|
|
|
143 |
title="# 🙋🏻♂️Welcome to🌟Tonic's🔮Goedel Prover📉",
|
144 |
description="""You can build with this endpoint using🔮Goedel-Prover-SFT📉 available here : [Goedel-LM/Goedel-Prover-SFT](https://huggingface.co/Goedel-LM/Goedel-Prover-SFT). We're using 🤖[introspector/unimath](https://huggingface.co/datasets/introspector/unimath) for cool examples, check it out below ! The demo is still a work in progress and we're looking forward to build downstream tasks that showcase outstanding mathematical reasoning. Have any ideas ? join us below !
|
145 |
You can also use 🔮Goedel Prover📉 by cloning this space. Simply click here: <a style="display:inline-block" href="https://huggingface.co/spaces/Tonic/Math?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></h3>
|
146 |
+
Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's 🛠️community 👻 [Join us on Discord](https://discord.gg/GWpVpekp) On 🤗Huggingface: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) Math with [introspector](https://huggingface.co/introspector) On 🌐Github: [Tonic-AI](https://github.com/tonic-ai) & contribute to🌟 [SciTonic](https://github.com/Tonic-AI/scitonic)🤗Big thanks to Yuvi Sharma and all the folks at huggingface for the community grant 🤗
|
147 |
""",
|
148 |
fn=solve_math_problem,
|
149 |
outputs=[
|
|
|
153 |
inputs=[
|
154 |
gr.Textbox(label="🤔Enter your Lean4 formal statement", lines=7),
|
155 |
gr.Textbox(value=additional_info_prompt, label="🪜Optional informal prefix"),
|
156 |
+
gr.Slider(minimum=150, maximum=4086, value=2500, label="🪙Max Tokens")
|
157 |
],
|
158 |
examples=examples
|
159 |
)
|