File size: 1,078 Bytes
eff99d8
ae152d5
aa36139
 
da2916f
eff99d8
 
938032f
 
 
 
 
 
aa36139
da2916f
 
 
 
aa36139
 
da2916f
aa36139
938032f
77b14f6
 
938032f
 
da2916f
eff99d8
aa36139
 
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
import os
os.environ["OMP_NUM_THREADS"] = "1"

import gradio as gr
from SLM_CService import chat_with_memory, reset_state

def respond(user_message, history):
    reply = chat_with_memory(user_message or "")
    history = (history or []) + [
        {"role":"user","content": user_message or ""},
        {"role":"assistant","content": reply},
    ]
    return history

def reset_chat():
    reset_state()          # <-- clear memory + globals
    return []              # clear UI

with gr.Blocks() as demo:
    gr.Markdown("# 🛎 Customer Support Chatbot")
    chatbot = gr.Chatbot(type="messages")
    with gr.Row():
        user_in = gr.Textbox(placeholder="Ask about orders, tracking, returns…", scale=5)
        send    = gr.Button("Send", variant="primary")
        reset   = gr.Button("🔄 Reset Chat")
    send.click(respond, [user_in, chatbot], [chatbot])
    user_in.submit(respond, [user_in, chatbot], [chatbot])
    reset.click(reset_chat, None, [chatbot])   # <-- real reset

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860)