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)