# Imports import gradio as gr from agent import agent # UI with gr.Blocks() as demo: # Centered title and description using HTML gr.HTML("""

🔧 TechSpark AI Assistant 🤖

Welcome to the TechSpark AI Assistant!
Ask anything about TechSpark staff, tools, courses or location of tools.

""") # Chatbot: no `type=` arg, but it STILL uses "messages" format internally chat = gr.Chatbot(height=420) inp = gr.Textbox( placeholder="Ask your question in natural language.", label="Your question" ) def respond(message, history): # history here is a list of {"role", "content"} dicts (messages format) if history is None: history = [] try: out = str(agent.run(message, reset=False)) except Exception as e: out = f"[Error] {e}" # APPEND MESSAGES AS DICTS, NOT LISTS/TUPLES history = history + [ {"role": "user", "content": message}, {"role": "assistant", "content": out}, ] # Clear input, update chat return "", history gr.Examples( examples=[ "Who is Ed?", "Who to talk to to create a wooden table?", "How to access the laser cutters?", "How to go to the welding space?", ], inputs=[inp], outputs=[inp, chat], fn=respond, cache_examples=False, ) inp.submit(respond, [inp, chat], [inp, chat]) demo.launch()