Tonic commited on
Commit
7aeb7f8
Β·
verified Β·
1 Parent(s): 2ccb1ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -36
app.py CHANGED
@@ -31,58 +31,28 @@ 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
- # 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()
39
 
40
- # Clean up any duplicate headers or content
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
 
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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  return '\n'.join(cleaned_lines)
53
  except Exception as e:
54
  print(f"Error in extract_code: {str(e)}")
55
+ return "Error processing code""
56
 
57
 
58
  # Example problems