broadfield-dev's picture
Update app.py
14140d0 verified
import gradio as gr
#from gradio.components.multimodal_textbox import MultimodalTextbox as mt_mod
from MultiModalTextbox_mods import MultimodalTextbox as mt_mod
print(mt_mod.EVENTS)
#mt_mod.EVENTS=[]
#mt_mod.EVENTS[3]
print(mt_mod.EVENTS)
elem_id = "chat_input"
js_script = f"""
function() {{
const ta = document.querySelector(`#{elem_id} > label > textarea`);
if (ta) {{
ta.addEventListener('keydown', (e) => {{
if (e.key === 'Enter' && !e.shiftKey) {{
e.preventDefault();
}}
}});
}}
}}
"""
with gr.Blocks() as demo:
chatbot = gr.Chatbot(label="Chatbot")
with gr.Row():
msg = mt_mod(
submit_btn=True,
elem_id=elem_id,
)
#submit_button = gr.Button("Submit")
# A single, robust function to handle both user and bot turns
def respond(user_message, chat_history):
return {"text": "Testing...", "files": []}
def newline(msg):
msg["text"] = msg.get("text", "") + "\n"
return msg
msg.submit(respond, inputs=msg, outputs=msg)
#submit_button.click(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
#demo.load(js=js_script)
if __name__ == "__main__":
demo.launch()