Spaces:
Running
Running
Update app.py
Browse files
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 |
-
#
|
| 50 |
-
for
|
| 51 |
-
if
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
| 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:
|