File size: 1,254 Bytes
31b8cd8
cd1f417
b6d002b
cd1f417
 
f7c3c81
 
8e79676
565ef6e
1db61bf
f7c3c81
31b8cd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a3d9c4
3963bee
31b8cd8
 
3963bee
31b8cd8
 
 
 
e7a64b9
31b8cd8
 
 
 
 
14140d0
6ec79e7
3963bee
31b8cd8
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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()