peterpeter8585 commited on
Commit
f4d296a
Β·
verified Β·
1 Parent(s): 873bb2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -454,6 +454,10 @@ def chat(message, history,username="default_user"):
454
 
455
  # βœ… Gradio용 μ±„νŒ… ν˜•μ‹ μ—…λ°μ΄νŠΈ
456
  history = history + [(message, output)]
 
 
 
 
457
  return history, history, ""
458
  '''
459
  def chat(message, history, hf_token):
@@ -492,15 +496,27 @@ def chat(message, history, hf_token):
492
  return history, history, "" # μž…λ ₯ μ΄ˆκΈ°ν™”
493
  '''
494
  # 예: hf_token (ν˜Ήμ€ username) 을 μž…λ ₯으둜 받도둝 λ³€κ²½
495
- def refresh_conversation_list(_=None):
 
496
  if not os.path.exists("user_logs"):
497
- return gr.update(choices=[], value=None)
498
  files = sorted(os.listdir("user_logs"), reverse=True)
499
  titles = [f.replace(".json", "") for f in files]
500
- return gr.update(choices=titles, value=titles[0] if titles else None)
501
-
502
  def load_selected(file):
503
- return load_conversation(file)
 
 
 
 
 
 
 
 
 
 
 
 
504
 
505
 
506
  # ──────────────────────────────
 
454
 
455
  # βœ… Gradio용 μ±„νŒ… ν˜•μ‹ μ—…λ°μ΄νŠΈ
456
  history = history + [(message, output)]
457
+ os.makedirs("user_logs", exist_ok=True)
458
+ file_path = os.path.join("user_logs", f"{username}_current.json")
459
+ with open(file_path, "w", encoding="utf-8") as f:
460
+ json.dump({"history": history}, f, ensure_ascii=False, indent=2)
461
  return history, history, ""
462
  '''
463
  def chat(message, history, hf_token):
 
496
  return history, history, "" # μž…λ ₯ μ΄ˆκΈ°ν™”
497
  '''
498
  # 예: hf_token (ν˜Ήμ€ username) 을 μž…λ ₯으둜 받도둝 λ³€κ²½
499
+ def refresh_conversation_list(*_):
500
+ """λŒ€ν™” λͺ©λ‘μ„ μƒˆλ‘œκ³ μΉ¨ (Gradio 호좜 λŒ€μ‘)"""
501
  if not os.path.exists("user_logs"):
502
+ return gr.Dropdown.update(choices=[], value=None)
503
  files = sorted(os.listdir("user_logs"), reverse=True)
504
  titles = [f.replace(".json", "") for f in files]
505
+ return gr.Dropdown.update(choices=titles, value=titles[0] if titles else None)
 
506
  def load_selected(file):
507
+ """μ„ νƒλœ λŒ€ν™”λ₯Ό λΆˆλŸ¬μ™€ μ΄μ–΄μ„œ λŒ€ν™”"""
508
+ path = os.path.join("user_logs", file)
509
+ if not os.path.exists(path):
510
+ return []
511
+ with open(path, "r", encoding="utf-8") as f:
512
+ data = json.load(f)
513
+ return data.get("history", [])
514
+
515
+
516
+
517
+
518
+
519
+
520
 
521
 
522
  # ──────────────────────────────