aslan-ng commited on
Commit
bb6b522
·
verified ·
1 Parent(s): 46a013c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -21
app.py CHANGED
@@ -741,29 +741,32 @@ agent = smolagents.CodeAgent(
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
- # IMPORTANT: no `type="messages"` here
762
  chat = gr.Chatbot(height=420)
763
- inp = gr.Textbox(placeholder="Ask your question in natural language.", label="Your question")
 
 
 
764
 
765
  def respond(message, history):
766
- # history is what goes into the Chatbot component
767
  if history is None:
768
  history = []
769
 
@@ -772,10 +775,13 @@ with gr.Blocks() as demo:
772
  except Exception as e:
773
  out = f"[Error] {e}"
774
 
775
- # For your Gradio version, history must be a list of [user, assistant] lists
776
- history.append([message, out])
 
 
 
777
 
778
- # Clear the input box, update chat
779
  return "", history
780
 
781
  gr.Examples(
 
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
+ # Chatbot: no `type=` arg, but it STILL uses "messages" format internally
762
  chat = gr.Chatbot(height=420)
763
+ inp = gr.Textbox(
764
+ placeholder="Ask your question in natural language.",
765
+ label="Your question"
766
+ )
767
 
768
  def respond(message, history):
769
+ # `history` here is a list of {"role", "content"} dicts (messages format)
770
  if history is None:
771
  history = []
772
 
 
775
  except Exception as e:
776
  out = f"[Error] {e}"
777
 
778
+ # APPEND MESSAGES AS DICTS, NOT LISTS/TUPLES
779
+ history = history + [
780
+ {"role": "user", "content": message},
781
+ {"role": "assistant", "content": out},
782
+ ]
783
 
784
+ # Clear input, update chat
785
  return "", history
786
 
787
  gr.Examples(