aedupuga commited on
Commit
8293c77
·
verified ·
1 Parent(s): 4769d5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -14
app.py CHANGED
@@ -521,38 +521,67 @@ agent = smolagents.CodeAgent(
521
  # --- Page config ---
522
  st.set_page_config(page_title="TechSpark AI Assistant", layout="wide")
523
 
524
- # --- Sidebar --
525
- import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
 
527
- # Minimal Gradio chat
528
- with gr.Blocks(title="TechSpark Agent") as demo:
529
- gr.Markdown("## Beam Agent — Custom Tool Selection (smolagents + llama.cpp)")
530
- chat = gr.Chatbot(height=420)
531
- inp = gr.Textbox(placeholder="Ask your question in natural language.", label="Your question")
 
 
532
 
533
- # No gr.State for agent — just close over `agent`
534
  def respond(message, history):
535
  try:
536
- # 1. Use agent.chat() to maintain internal history
537
  out = str(agent.run(message))
538
  except Exception as e:
539
  out = f"[Error] {e}"
540
 
541
- # This just updates the Gradio UI history
542
  history = (history or []) + [(message, out)]
543
  return "", history
544
 
 
545
  gr.Examples(
546
- fn=respond,
547
  examples=[
548
  "Who is Ed?",
549
  "Who to talk to to create a wooden table?",
550
- "how to access laser cutter"
551
  ],
552
- inputs=[inp]
 
 
553
  )
554
 
 
555
  inp.submit(respond, [inp, chat], [inp, chat])
556
 
 
 
 
 
557
 
558
- demo.launch(debug=True)
 
521
  # --- Page config ---
522
  st.set_page_config(page_title="TechSpark AI Assistant", layout="wide")
523
 
524
+ #import gradio as gr
525
+
526
+ # Minimal Gradio chat for TechSpark Agent
527
+ with gr.Blocks(
528
+ title="TechSpark AI Assistant",
529
+ theme=gr.themes.Soft(), # Soft, modern theme
530
+ ) as demo:
531
+
532
+ # --- Header / description ---
533
+ gr.Markdown(
534
+ """
535
+ # 🤖 TechSpark AI Assistant
536
+ Welcome to the TechSpark AI Assistant!
537
+
538
+ Ask anything about **TechSpark staff, tools, courses**, or machine usage.
539
+ The agent is powered by **smolagents** and uses the internal knowledge of our facility to give you fast, relevant answers.
540
+
541
+ 💡 Example questions you can try:
542
+ - "Who is Ed?"
543
+ - "Who should I talk to for building a wooden table?"
544
+ - "How do I access the laser cutter?"
545
+ """
546
+ )
547
 
548
+ # --- Chat interface ---
549
+ chat = gr.Chatbot(label="TechSpark Assistant", height=450)
550
+ inp = gr.Textbox(
551
+ placeholder="Type your question here...",
552
+ label="Your question",
553
+ interactive=True
554
+ )
555
 
556
+ # --- Function to respond ---
557
  def respond(message, history):
558
  try:
559
+ # Use agent.run() to maintain internal state
560
  out = str(agent.run(message))
561
  except Exception as e:
562
  out = f"[Error] {e}"
563
 
564
+ # Append to chat history
565
  history = (history or []) + [(message, out)]
566
  return "", history
567
 
568
+ # --- Examples for quick testing ---
569
  gr.Examples(
 
570
  examples=[
571
  "Who is Ed?",
572
  "Who to talk to to create a wooden table?",
573
+ "How to access the laser cutter"
574
  ],
575
+ inputs=[inp],
576
+ fn=respond,
577
+ cache_examples=True
578
  )
579
 
580
+ # --- Connect input to chat ---
581
  inp.submit(respond, [inp, chat], [inp, chat])
582
 
583
+ # Launch the demo
584
+ demo.launch()
585
+
586
+
587