-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_ui.py
More file actions
93 lines (73 loc) · 2.9 KB
/
Copy pathpatch_ui.py
File metadata and controls
93 lines (73 loc) · 2.9 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
patch_ui.py — SynthForge UI Redesign Patch
============================================
Reads new_ui_section.py and splices it into hf_space/app.py,
replacing everything from the UI anchor to end of file.
Also patches generate_suggestions to produce 6 suggestions.
Run from C:\\Users\\Ezeking\\SynthForge:
python patch_ui.py
Requires new_ui_section.py in the same directory as this script.
Creates app.py.bak2 before touching anything.
"""
import shutil
import sys
from pathlib import Path
APP_PATH = Path(r"C:\Users\Ezeking\hf_space\app.py")
BACKUP_PATH = APP_PATH.with_suffix(".py.bak2")
NEW_UI_PATH = Path(__file__).parent / "new_ui_section.py"
UI_ANCHOR = (
"# ---------------------------------------------------------------------------\n"
"# UI\n"
"# ---------------------------------------------------------------------------"
)
SUGG_PATCHES = [
(
'"Generate exactly 3 prompt-engineering follow-up questions. "\n'
' "Return ONLY a JSON array of 3 strings."\n',
'"Generate exactly 6 prompt-engineering follow-up questions. "\n'
' "Return ONLY a JSON array of 6 strings."\n',
"generate_suggestions: 3 -> 6",
),
(
'"max_tokens": 150,',
'"max_tokens": 300,',
"generate_suggestions: max_tokens 150 -> 300",
),
]
def patch_once(content: str, find: str, replace: str, label: str) -> str:
if find not in content:
print(f"\n x FAILED [{label}] -- anchor not found:")
print(f" {find[:100]!r}")
sys.exit(1)
print(f" ok {label}")
return content.replace(find, replace, 1)
def main() -> None:
for path, name in [(APP_PATH, "app.py"), (NEW_UI_PATH, "new_ui_section.py")]:
if not path.exists():
print(f"ERROR: {name} not found at {path}")
sys.exit(1)
print(f"\nSynthForge UI Redesign Patch")
print(f"Target : {APP_PATH}")
print(f"New UI : {NEW_UI_PATH}\n")
content = APP_PATH.read_text(encoding="utf-8")
new_ui_text = NEW_UI_PATH.read_text(encoding="utf-8")
shutil.copy(APP_PATH, BACKUP_PATH)
print(f"Backup : {BACKUP_PATH}\n")
print("Applying patches:")
for find, replace, label in SUGG_PATCHES:
content = patch_once(content, find, replace, label)
anchor_pos = content.find(UI_ANCHOR)
if anchor_pos == -1:
print("\n x FAILED [UI anchor] -- not found in app.py")
sys.exit(1)
content = content[:anchor_pos] + new_ui_text
print(" ok UI section replaced with new layout")
APP_PATH.write_text(content, encoding="utf-8")
print(f"\nAll patches applied. {APP_PATH.name} updated.")
print("\nNow run:")
print(r" cd C:\Users\Ezeking\hf_space")
print(r" git add app.py")
print(r' git commit -m "UI: attach inline, Griot top-right, metrics strip, 6 suggestions, numbered history"')
print(r" git push")
if __name__ == "__main__":
main()