aslan-ng commited on
Commit
e1e2259
·
verified ·
1 Parent(s): 99a3c78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -35
app.py CHANGED
@@ -739,39 +739,32 @@ agent = smolagents.CodeAgent(
739
  max_steps=10,
740
  verbosity_level=2, # show steps in logs for class demo
741
  )
742
-
743
- with gr.Blocks() as demo:
744
-
745
- # Centered title and description using HTML
746
- gr.HTML("""
747
- <div style="text-align: center; font-family: 'Arial', sans-serif;">
748
- <h1 style="color:#1f77b4; margin-bottom: 20px; font-weight: 300;">
749
- 🤖 TechSpark AI Assistant
750
- </h1>
751
-
752
- <p style="margin-top: 0; font-weight: 300; font-size: 16px; color:#555;">
753
- Welcome to the TechSpark AI Assistant!<br>
754
- Ask anything about TechSpark staff, tools, courses or location of tools.<br>
755
- This assistant is powered by OpenAI's GPT model via smolagents,
756
- accessing accurate information from our curated dataset verified by TechSpark staff!
757
- </p>
758
- </div>
759
- """)
760
-
761
- chat = gr.Chatbot(height=420)
762
- inp = gr.Textbox(placeholder="Ask your question in natural language.", label="Your question")
763
 
764
- # No gr.State for agent just close over `agent`
765
- def respond(message, history):
766
- try:
767
- # 1. Use agent.chat() to maintain internal history
768
- out = str(agent.run(message))
769
- except Exception as e:
770
- out = f"[Error] {e}"
 
 
 
 
 
 
 
 
 
 
771
 
772
- # This just updates the Gradio UI history
773
- history = (history or []) + [(message, out)]
774
- return "", history
 
 
 
 
775
 
776
  gr.Examples(
777
  examples=[
@@ -783,9 +776,7 @@ with gr.Blocks() as demo:
783
  inputs=[inp],
784
  outputs=[inp, chat],
785
  fn=respond,
786
- cache_examples=False, # Set to False for dynamic content or to avoid caching issues
787
  )
788
 
789
- inp.submit(respond, [inp, chat], [inp, chat])
790
-
791
- demo.launch()
 
739
  max_steps=10,
740
  verbosity_level=2, # show steps in logs for class demo
741
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
742
 
743
+ chat = gr.Chatbot(height=420, type="messages") # make it explicit it's messages-format
744
+
745
+ def respond(message, history):
746
+ try:
747
+ out = str(agent.run(message))
748
+ except Exception as e:
749
+ out = f"[Error] {e}"
750
+
751
+ if history is None:
752
+ history = []
753
+
754
+ # history is now a list of {"role": ..., "content": ...} dicts
755
+ history = history + [
756
+ {"role": "user", "content": message},
757
+ {"role": "assistant", "content": out},
758
+ ]
759
+ return "", history
760
 
761
+ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
762
+ gr.HTML("""...""")
763
+
764
+ chat = gr.Chatbot(height=420, type="messages")
765
+ inp = gr.Textbox(placeholder="Ask your question in natural language.", label="Your question")
766
+
767
+ inp.submit(respond, [inp, chat], [inp, chat])
768
 
769
  gr.Examples(
770
  examples=[
 
776
  inputs=[inp],
777
  outputs=[inp, chat],
778
  fn=respond,
779
+ cache_examples=False,
780
  )
781
 
782
+ demo.launch()