Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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
|
32 |
-
|
33 |
-
if
|
34 |
return response.strip()
|
35 |
|
36 |
-
# Get
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
#
|
40 |
-
lines =
|
41 |
cleaned_lines = []
|
42 |
|
43 |
for line in lines:
|
44 |
-
# Skip empty lines at
|
45 |
if not cleaned_lines and not line.strip():
|
46 |
continue
|
47 |
-
# Skip
|
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)
|