Ricky01anjay commited on
Commit
5eb5439
Β·
verified Β·
1 Parent(s): f10c568

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -52,8 +52,15 @@ def update_job(jid: str, **kwargs):
52
  # ALGORITMA FIND & CHANGE
53
  # ─────────────────────────────────────────────
54
 
55
- def decode_html_entities(text: str) -> str:
56
- """Perbaiki jika AI mengembalikan HTML yang ter-escape secara tidak sengaja."""
 
 
 
 
 
 
 
57
  return (text.replace('&', '&')
58
  .replace('&lt;', '<')
59
  .replace('&gt;', '>')
@@ -151,9 +158,9 @@ def apply_find_change(code_base: str, ai_response: str) -> dict:
151
  if not el_match or not ch_match:
152
  raise ValueError(f"Blok <find> ke-{i+1} formatnya salah (kehilangan element/change).")
153
 
154
- # Decode entitas HTML yang mungkin tersalin sebagai &lt; dsb
155
- old_code = decode_html_entities(el_match.group(1))
156
- new_code = decode_html_entities(ch_match.group(1))
157
 
158
  old_code_trimmed = old_code.strip()
159
 
@@ -721,6 +728,5 @@ HTML = r"""<!DOCTYPE html>
721
  def index():
722
  return Response(HTML, mimetype="text/html")
723
 
724
-
725
  if __name__ == "__main__":
726
  app.run(host="0.0.0.0", port=7860)
 
52
  # ALGORITMA FIND & CHANGE
53
  # ─────────────────────────────────────────────
54
 
55
+ def normalize_ai_text(text: str) -> str:
56
+ """
57
+ 1. Mengubah literal '\n', '\t', '\r' dari AI menjadi karakter whitespace asli.
58
+ 2. Memperbaiki jika AI mengembalikan HTML yang ter-escape secara tidak sengaja.
59
+ """
60
+ # Ubah literal escape menjadi karakter sesungguhnya
61
+ text = text.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
62
+
63
+ # Decode HTML Entities
64
  return (text.replace('&amp;', '&')
65
  .replace('&lt;', '<')
66
  .replace('&gt;', '>')
 
158
  if not el_match or not ch_match:
159
  raise ValueError(f"Blok <find> ke-{i+1} formatnya salah (kehilangan element/change).")
160
 
161
+ # Normalisasi: Ubah literal \n jadi newline asli & decode entitas HTML
162
+ old_code = normalize_ai_text(el_match.group(1))
163
+ new_code = normalize_ai_text(ch_match.group(1))
164
 
165
  old_code_trimmed = old_code.strip()
166
 
 
728
  def index():
729
  return Response(HTML, mimetype="text/html")
730
 
 
731
  if __name__ == "__main__":
732
  app.run(host="0.0.0.0", port=7860)