TechSpark_AI / app.py
aslan-ng's picture
Update app.py
cdf5103 verified
# Imports
import gradio as gr
from agent import agent
# UI
with gr.Blocks() as demo:
# Centered title and description using HTML
gr.HTML("""
<style>footer {display: none !important;} .flex.gap-4 a {display: none !important;}</style>
<div style="text-align: center; font-family: 'Arial', sans-serif;">
<h1 style="color:#1f77b4; margin-bottom: 20px; font-weight: 300;">
🔧 TechSpark AI Assistant 🤖
</h1>
<p style="margin-top: 0; font-weight: 300; font-size: 16px; color:#555;">
Welcome to the TechSpark AI Assistant!<br>
Ask anything about TechSpark staff, tools, courses or location of tools.<br>
</p>
</div>
""")
# 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()