Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(_
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
# ββββββββββββββββββββββββββββββ
|