Eyadddddddd commited on
Commit
b07e40c
·
verified ·
1 Parent(s): cd5ee6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -39,19 +39,21 @@ def image_to_ascii(image_path, width=100):
39
  return "\n".join(ascii_lines)
40
 
41
  # =========================
42
- # CHAT FUNCTION
43
  # =========================
44
 
45
  def chat_fn(message, history, mode="Normal Chat", model=DEFAULT_MODEL, image=None, include_ascii=False):
46
  try:
47
  messages = [{"role": "system", "content": MODE_PROMPTS.get(mode, MODE_PROMPTS["Normal Chat"])}]
48
 
49
- # Add chat history
50
- for user_msg, assistant_msg in history:
51
- if user_msg:
52
- messages.append({"role": "user", "content": user_msg})
53
- if assistant_msg:
54
- messages.append({"role": "assistant", "content": assistant_msg})
 
 
55
 
56
  # If image uploaded + toggle ON → convert to ASCII
57
  if image and include_ascii:
 
39
  return "\n".join(ascii_lines)
40
 
41
  # =========================
42
+ # CHAT FUNCTION (WITH HISTORY FIX)
43
  # =========================
44
 
45
  def chat_fn(message, history, mode="Normal Chat", model=DEFAULT_MODEL, image=None, include_ascii=False):
46
  try:
47
  messages = [{"role": "system", "content": MODE_PROMPTS.get(mode, MODE_PROMPTS["Normal Chat"])}]
48
 
49
+ # SAFELY process history (fixes "too many values to unpack")
50
+ for pair in history:
51
+ if isinstance(pair, list) and len(pair) == 2:
52
+ user_msg, assistant_msg = pair
53
+ if isinstance(user_msg, str) and user_msg.strip():
54
+ messages.append({"role": "user", "content": user_msg})
55
+ if isinstance(assistant_msg, str) and assistant_msg.strip():
56
+ messages.append({"role": "assistant", "content": assistant_msg})
57
 
58
  # If image uploaded + toggle ON → convert to ASCII
59
  if image and include_ascii: