june-woo commited on
Commit
49f79f9
·
1 Parent(s): ca7d9e2

프로필편집오류 수정 #14

Browse files
Files changed (1) hide show
  1. gradio_app.py +22 -13
gradio_app.py CHANGED
@@ -1150,37 +1150,46 @@ def save_persona_edits(
1150
  response_style,
1151
  key_principles_text,
1152
  famous_quotes_text,
1153
- image_path="" # ✅ 변경
1154
  ) -> str:
1155
 
1156
  if not original_name or original_name == "없음":
1157
  return "Select a persona to save."
1158
 
1159
  try:
1160
- personas = _parse_personas()
 
 
 
 
 
 
 
 
 
 
 
 
1161
  updated = False
1162
  new_lines = []
1163
 
1164
- for p in personas:
1165
- if p.name.strip() == original_name:
1166
- d = _persona_to_dict(p)
1167
-
1168
- # 🔥 핵심: image_path 직접 저장
1169
- d["image_path"] = image_path.strip() or d.get("image_path")
1170
-
1171
- d["name"] = new_name.strip() or d["name"]
1172
- d["full_name"] = full_name.strip() or d["full_name"]
1173
  d["summary"] = summary.strip()
1174
  d["financial_mindset"] = financial_mindset.strip()
1175
  d["data_analysis_approach"] = data_analysis_approach.strip()
1176
  d["response_style"] = response_style.strip()
1177
  d["key_principles"] = [x.strip() for x in key_principles_text.split("\n") if x.strip()]
1178
  d["famous_quotes"] = [x.strip() for x in famous_quotes_text.split("\n") if x.strip()] or None
1179
-
 
1180
  new_lines.append(json.dumps(d, ensure_ascii=False))
1181
  updated = True
1182
  else:
1183
- new_lines.append(json.dumps(_persona_to_dict(p), ensure_ascii=False))
1184
 
1185
  if not updated:
1186
  return "No corresponding persona found."
 
1150
  response_style,
1151
  key_principles_text,
1152
  famous_quotes_text,
1153
+ image_path=""
1154
  ) -> str:
1155
 
1156
  if not original_name or original_name == "없음":
1157
  return "Select a persona to save."
1158
 
1159
  try:
1160
+ # raw dict로 읽어서 saved_at, query 등 extra 필드 보존
1161
+ raw_lines = []
1162
+ if PERSONA_FILE.exists():
1163
+ with PERSONA_FILE.open("r", encoding="utf-8") as f:
1164
+ for line in f:
1165
+ line = line.strip()
1166
+ if not line:
1167
+ continue
1168
+ try:
1169
+ raw_lines.append(json.loads(line))
1170
+ except json.JSONDecodeError:
1171
+ continue
1172
+
1173
  updated = False
1174
  new_lines = []
1175
 
1176
+ for d in raw_lines:
1177
+ if d.get("name", "").strip() == original_name:
1178
+ # extra 필드(saved_at, query 등)는 그대로 두고 편집 필드만 덮어쓰기
1179
+ d["name"] = new_name.strip() or d.get("name", "")
1180
+ d["full_name"] = full_name.strip() or d.get("full_name", "")
 
 
 
 
1181
  d["summary"] = summary.strip()
1182
  d["financial_mindset"] = financial_mindset.strip()
1183
  d["data_analysis_approach"] = data_analysis_approach.strip()
1184
  d["response_style"] = response_style.strip()
1185
  d["key_principles"] = [x.strip() for x in key_principles_text.split("\n") if x.strip()]
1186
  d["famous_quotes"] = [x.strip() for x in famous_quotes_text.split("\n") if x.strip()] or None
1187
+ if image_path.strip():
1188
+ d["image_path"] = image_path.strip()
1189
  new_lines.append(json.dumps(d, ensure_ascii=False))
1190
  updated = True
1191
  else:
1192
+ new_lines.append(json.dumps(d, ensure_ascii=False))
1193
 
1194
  if not updated:
1195
  return "No corresponding persona found."