Spaces:
Sleeping
Sleeping
File size: 1,579 Bytes
d1d1019 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import os
def fix_app():
path = "app.py"
with open(path, 'r', encoding='utf-8') as f:
lines = f.readlines()
new_lines = []
skip = False
found = False
for i, line in enumerate(lines):
# Check for the zombie block start
if "pred_rf2 =" in line and "self.rf2.predict" in line:
print(f"Found zombie line at {i+1}: {line.strip()}")
skip = True
found = True
# Heuristic to stop skipping: if we hit a def/class or specific known next line
if skip:
if "def predict_proba" in line: # Also zombie
continue
if line.strip() == "": # Keep empty lines?
pass
if "# =====================================================================" in line: # Next section
skip = False
elif "def " in line and "predict_proba" not in line: # New method
skip = False
if not skip:
new_lines.append(line)
else:
print(f"Removing: {line.strip()}")
if found:
with open(path, 'w', encoding='utf-8') as f:
f.writelines(new_lines)
print("Fixed app.py")
else:
print("No zombie lines found in app.py via python script.")
# Print lines around 188 to debug
start = max(0, 180)
end = min(len(lines), 200)
print(f"Lines {start}-{end}:")
for j in range(start, end):
print(f"{j+1}: {lines[j].rstrip()}")
if __name__ == "__main__":
fix_app()
|