You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am experiencing an issue where the HTML tags in my input are stripped when using the Oobabooga Text Generation Web UI. I need to ensure that specific HTML tags such as <h2>, <h3>, <b>, <i>, <u>, <a>, and <p> are preserved in the chat input and output. This is essential for maintaining the formatting of the content I am working with.
I'm using Chat-Instruct mode.
I know very little about coding. So, I loaded up ChatGPT, and it gave me the instructions below. I followed them, and as it turns out, OobaBooga did not start when I loaded up start_linux.sh.
Appreciate it if someone could help me figure this out.
ChatGPT Instructions (which did not work)....and it was actually my idea to ask ChatGPT to apply some sort of sanitization. I may not know a ton about coding...but I know having the ability to enter HTML willy-nilly in a chat box is asking for trouble. Even though I do password protect my web server (which is only online when I'm online working).:
To preserve HTML tags in the chat input in Oobabooga, you need to modify the ui_chat.py file. The following steps outline how to implement the solution:
1. Import the bleach Library.
Add the bleach library to sanitize and preserve the desired HTML tags.
2. Create a Function to Sanitize Input:
Define a function to clean the input while allowing specific HTML tags and attributes.
3. Modify the Chat Input Handling:
Adjust the chat input processing to use the sanitization function.
Here’s the complete code for ui_chat.py with the necessary changes:
import json
from functools import partial
from pathlib import Path
import gradio as gr
from PIL import Image
from modules import chat, shared, ui, utils
from modules.html_generator import chat_html_wrapper
from modules.text_generation import stop_everything_event
from modules.utils import gradio
import bleach # Add this line
def sanitize_input(input_text):
allowed_tags = ['b', 'i', 'u', 'a', 'h2', 'h3', 'p']
allowed_attributes = {'a': ['href', 'title']}
clean_text = bleach.clean(input_text, tags=allowed_tags, attributes=allowed_attributes)
return clean_text
inputs = ('Chat input', 'interface_state')
reload_arr = ('history', 'name1', 'name2', 'mode', 'chat_style', 'character_menu')
clear_arr = ('delete_chat-confirm', 'delete_chat', 'delete_chat-cancel')
def create_ui():
mu = shared.args.multi_user
shared.gradio['Chat input'] = gr.State()
shared.gradio['history'] = gr.State({'internal': [], 'visible': []})
with gr.Tab('Chat', elem_id='chat-tab', elem_classes=("old-ui" if shared.args.chat_buttons else None)):
with gr.Row():
with gr.Column(elem_id='chat-col'):
shared.gradio['display'] = gr.HTML(value=chat_html_wrapper({'internal': [], 'visible': []}, '', '', 'chat', 'cai-chat', ''))
with gr.Row(elem_id="chat-input-row"):
with gr.Column(scale=1, elem_id='gr-hover-container'):
gr.HTML(value='<div class="hover-element" onclick="void(0)"><span style="width: 100px; display: block" id="hover-element-button">☰</span><div class="hover-menu" id="hover-menu"></div>', elem_id='gr-hover')
# Import the sanitize_input function
from modules.ui_chat import sanitize_input # Add this line
# Define the function to process the chat response
def generate_chat_reply(text, state, regenerate=False, _continue=False, loading_message=True, for_ui=False):
sanitized_text = sanitize_input(text)
bot_response = f"<h2>{sanitized_text}</h2>"
return state['history'] + [(sanitized_text, bot_response)]
I just cut and paste and saved the file. When it didn't work, I reverted what I did and everything went back to working.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am experiencing an issue where the HTML tags in my input are stripped when using the Oobabooga Text Generation Web UI. I need to ensure that specific HTML tags such as
<h2>, <h3>, <b>, <i>, <u>, <a>, and <p>
are preserved in the chat input and output. This is essential for maintaining the formatting of the content I am working with.I'm using Chat-Instruct mode.
I know very little about coding. So, I loaded up ChatGPT, and it gave me the instructions below. I followed them, and as it turns out, OobaBooga did not start when I loaded up start_linux.sh.
Appreciate it if someone could help me figure this out.
ChatGPT Instructions (which did not work)....and it was actually my idea to ask ChatGPT to apply some sort of sanitization. I may not know a ton about coding...but I know having the ability to enter HTML willy-nilly in a chat box is asking for trouble. Even though I do password protect my web server (which is only online when I'm online working).:
To preserve HTML tags in the chat input in Oobabooga, you need to modify the ui_chat.py file. The following steps outline how to implement the solution:
Add the bleach library to sanitize and preserve the desired HTML tags.
2. Create a Function to Sanitize Input:
Define a function to clean the input while allowing specific HTML tags and attributes.
3. Modify the Chat Input Handling:
Adjust the chat input processing to use the sanitization function.
Here’s the complete code for ui_chat.py with the necessary changes:
I just cut and paste and saved the file. When it didn't work, I reverted what I did and everything went back to working.
Beta Was this translation helpful? Give feedback.
All reactions