Tonic commited on
Commit
946d1a8
Β·
verified Β·
1 Parent(s): ee01cfa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -24,27 +24,32 @@ def format_prompt(formal_statement, informal_prefix=""):
24
  f"{informal_prefix}\n"
25
  f"{formal_statement}"
26
  )
27
-
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 response.strip()
35
 
36
- # Get the last complete response
37
- full_content = matches[-1].strip()
 
 
 
 
 
38
 
39
- # Split into lines and clean up
40
- lines = full_content.split('\n')
41
  cleaned_lines = []
42
 
43
  for line in lines:
44
- # Skip empty lines at the start
45
  if not cleaned_lines and not line.strip():
46
  continue
47
- # Skip lines containing "Complete the following"
48
  if "Complete the following" in line:
49
  continue
50
  cleaned_lines.append(line)
 
24
  f"{informal_prefix}\n"
25
  f"{formal_statement}"
26
  )
27
+
28
  def extract_code(response):
29
  """Extract code between lean4 code blocks and the model's output"""
30
  try:
31
+ # Find the last occurrence of ```lean4 and extract everything until the last ```
32
+ start_idx = response.rfind("```lean4")
33
+ if start_idx == -1:
34
  return response.strip()
35
 
36
+ # Get content after ```lean4
37
+ content = response[start_idx + 7:]
38
+
39
+ # Find the last closing ```
40
+ end_idx = content.rfind("```")
41
+ if end_idx != -1:
42
+ content = content[:end_idx]
43
 
44
+ # Clean up the content
45
+ lines = content.split('\n')
46
  cleaned_lines = []
47
 
48
  for line in lines:
49
+ # Skip empty lines at start
50
  if not cleaned_lines and not line.strip():
51
  continue
52
+ # Skip "Complete the following" lines
53
  if "Complete the following" in line:
54
  continue
55
  cleaned_lines.append(line)