Tonic commited on
Commit
2ccb1ee
·
verified ·
1 Parent(s): d0b4b02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -12
app.py CHANGED
@@ -12,7 +12,7 @@ LEAN4_DEFAULT_HEADER = (
12
  "open BigOperators Real Nat Topology Rat\n"
13
  )
14
 
15
- title = """# 🙋🏻‍♂️Welcome to🌟Tonic's🔮Goedel Prover📉
16
  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)."""
17
 
18
  def format_prompt(formal_statement, informal_prefix=""):
@@ -31,7 +31,8 @@ def extract_code(response):
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 complete response including the model output
37
  full_content = matches[-1].strip()
@@ -40,28 +41,49 @@ def extract_code(response):
40
  lines = full_content.split('\n')
41
  cleaned_lines = []
42
  seen_headers = set()
 
43
 
44
  for line in lines:
45
  # Skip empty lines at the start
46
  if not cleaned_lines and not line.strip():
47
  continue
48
- # Skip duplicate headers and "Complete the following..." text
49
- if any(header in line for header in ["import Mathlib", "import Aesop", "set_option", "Complete the following"]):
50
- if line in seen_headers:
51
- continue
52
- seen_headers.add(line)
53
- # Skip duplicate goal statements
 
 
 
 
 
 
 
 
54
  if "Goal:" in line and line in cleaned_lines:
55
  continue
56
- cleaned_lines.append(line)
 
57
 
58
  # Remove any trailing "Complete the following..." text
59
  while cleaned_lines and "Complete the following" in cleaned_lines[-1]:
60
  cleaned_lines.pop()
61
 
 
 
 
 
 
 
 
 
 
62
  return '\n'.join(cleaned_lines)
63
- except:
64
- return "None"
 
 
65
 
66
  # Example problems
67
  unimath1 = """Goal:
@@ -145,7 +167,7 @@ def solve_math_problem(question, informal_prefix, max_tokens):
145
 
146
  def main():
147
  iface = gr.Interface(
148
- title="# 🙋🏻‍♂️Welcome to🌟Tonic's🔮Goedel Prover📉",
149
  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 !
150
  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>
151
  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 🤗
 
12
  "open BigOperators Real Nat Topology Rat\n"
13
  )
14
 
15
+ title = """🙋🏻‍♂️Welcome to🌟Tonic's🔮Goedel Prover📉
16
  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)."""
17
 
18
  def format_prompt(formal_statement, informal_prefix=""):
 
31
  # Find all content between ```lean4 and ``` tags
32
  matches = re.findall(r'```lean4(.*?)```', response, re.DOTALL)
33
  if not matches:
34
+ # If no matches found in code blocks, return the full response
35
+ return response.strip()
36
 
37
  # Get the last complete response including the model output
38
  full_content = matches[-1].strip()
 
41
  lines = full_content.split('\n')
42
  cleaned_lines = []
43
  seen_headers = set()
44
+ header_done = False
45
 
46
  for line in lines:
47
  # Skip empty lines at the start
48
  if not cleaned_lines and not line.strip():
49
  continue
50
+
51
+ # Process headers only once
52
+ if not header_done and any(header in line for header in ["import Mathlib", "import Aesop", "set_option", "open BigOperators"]):
53
+ if line not in seen_headers:
54
+ seen_headers.add(line)
55
+ cleaned_lines.append(line)
56
+ continue
57
+
58
+ # Mark header section as complete after processing imports and settings
59
+ if not header_done and cleaned_lines:
60
+ header_done = True
61
+ cleaned_lines.append("") # Add a blank line after headers
62
+
63
+ # Include the line if it's not a duplicate goal statement
64
  if "Goal:" in line and line in cleaned_lines:
65
  continue
66
+ if "Complete the following" not in line:
67
+ cleaned_lines.append(line)
68
 
69
  # Remove any trailing "Complete the following..." text
70
  while cleaned_lines and "Complete the following" in cleaned_lines[-1]:
71
  cleaned_lines.pop()
72
 
73
+ # Ensure the model's output is included
74
+ if "===========================" in full_content:
75
+ output_start = full_content.find("============================")
76
+ if output_start != -1:
77
+ output_text = full_content[output_start:].strip()
78
+ if ":= by" in output_text:
79
+ proof_part = output_text[output_text.find(":= by"):]
80
+ cleaned_lines.append(proof_part)
81
+
82
  return '\n'.join(cleaned_lines)
83
+ except Exception as e:
84
+ print(f"Error in extract_code: {str(e)}")
85
+ return "Error processing code"
86
+
87
 
88
  # Example problems
89
  unimath1 = """Goal:
 
167
 
168
  def main():
169
  iface = gr.Interface(
170
+ title="🙋🏻‍♂️Welcome to🌟Tonic's🔮Goedel Prover📉",
171
  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 !
172
  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>
173
  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 🤗