Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -103,14 +103,24 @@ with gr.Blocks() as demo:
|
|
| 103 |
ascii_toggle = gr.Checkbox(label="Convert image to ASCII art")
|
| 104 |
|
| 105 |
def respond(msg, chat_history, mode, model, img, ascii_on):
|
| 106 |
-
# 1. Get the bot's response
|
| 107 |
bot_message = chat_fn(msg, chat_history, mode, model, img, ascii_on)
|
| 108 |
|
| 109 |
-
# 2. Append the new interaction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
chat_history.append({"role": "user", "content": msg})
|
|
|
|
|
|
|
| 111 |
chat_history.append({"role": "assistant", "content": bot_message})
|
| 112 |
|
| 113 |
-
# 3. Return history and clear the input box
|
| 114 |
return chat_history, ""
|
| 115 |
|
| 116 |
send_btn.click(
|
|
|
|
| 103 |
ascii_toggle = gr.Checkbox(label="Convert image to ASCII art")
|
| 104 |
|
| 105 |
def respond(msg, chat_history, mode, model, img, ascii_on):
|
| 106 |
+
# 1. Get the bot's response (this includes the ASCII art in the message string)
|
| 107 |
bot_message = chat_fn(msg, chat_history, mode, model, img, ascii_on)
|
| 108 |
|
| 109 |
+
# 2. Append the new interaction to the chat history
|
| 110 |
+
# First, add the ASCII art as a separate, formatted block if it exists
|
| 111 |
+
if img and ascii_on:
|
| 112 |
+
ascii_art = image_to_ascii(img)
|
| 113 |
+
if ascii_art:
|
| 114 |
+
# Use gr.Code to display the ASCII art with proper formatting
|
| 115 |
+
chat_history.append({"role": "user", "content": gr.Code(ascii_art, language="text")})
|
| 116 |
+
|
| 117 |
+
# Then, add the user's text message
|
| 118 |
chat_history.append({"role": "user", "content": msg})
|
| 119 |
+
|
| 120 |
+
# Finally, add the assistant's response
|
| 121 |
chat_history.append({"role": "assistant", "content": bot_message})
|
| 122 |
|
| 123 |
+
# 3. Return the updated history and clear the input box
|
| 124 |
return chat_history, ""
|
| 125 |
|
| 126 |
send_btn.click(
|