aslan-ng commited on
Commit
96742cc
·
verified ·
1 Parent(s): 2a7d9c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -1
app.py CHANGED
@@ -8,6 +8,7 @@ from datasets import Dataset, DatasetDict, load_dataset
8
  import difflib
9
  import openai
10
  from langchain_community.utilities.wikipedia import WikipediaAPIWrapper
 
11
 
12
  REPO_ID_TECHSPARK_STAFF = "aslan-ng/CMU_TechSpark_Staff"
13
  REPO_ID_TECHSPARK_COURSES = "aslan-ng/CMU_TechSpark_Courses"
@@ -732,4 +733,38 @@ agent = smolagents.CodeAgent(
732
  add_base_tools=False,
733
  max_steps=10,
734
  verbosity_level=2, # show steps in logs for class demo
735
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  import difflib
9
  import openai
10
  from langchain_community.utilities.wikipedia import WikipediaAPIWrapper
11
+ import gradio as gr
12
 
13
  REPO_ID_TECHSPARK_STAFF = "aslan-ng/CMU_TechSpark_Staff"
14
  REPO_ID_TECHSPARK_COURSES = "aslan-ng/CMU_TechSpark_Courses"
 
733
  add_base_tools=False,
734
  max_steps=10,
735
  verbosity_level=2, # show steps in logs for class demo
736
+ )
737
+
738
+ with gr.Blocks(title="TechSpark Agent") as demo:
739
+ gr.Markdown("## Beam Agent — Custom Tool Selection (smolagents)")
740
+ chat = gr.Chatbot(height=420)
741
+ inp = gr.Textbox(placeholder="Ask your question in natural language.", label="Your question")
742
+
743
+ # No gr.State for agent — just close over `agent`
744
+ def respond(message, history):
745
+ try:
746
+ # 1. Use agent.chat() to maintain internal history
747
+ out = str(agent.run(message))
748
+ except Exception as e:
749
+ out = f"[Error] {e}"
750
+
751
+ # This just updates the Gradio UI history
752
+ history = (history or []) + [(message, out)]
753
+ return "", history
754
+
755
+ gr.Examples(
756
+ examples=[
757
+ "Who is Ed?",
758
+ "Who to talk to to create a wooden table?",
759
+ "Can I use laser cutters?",
760
+ "Where is welding space?"
761
+ ],
762
+ inputs=[inp],
763
+ outputs=[inp, chat],
764
+ fn=respond,
765
+ cache_examples=False, # Set to False for dynamic content or to avoid caching issues
766
+ )
767
+
768
+ inp.submit(respond, [inp, chat], [inp, chat])
769
+
770
+ demo.launch(share=True)