aedupuga commited on
Commit
9bcaa42
·
verified ·
1 Parent(s): 567cc0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -29
app.py CHANGED
@@ -7,10 +7,7 @@ from datasets import Dataset, DatasetDict, load_dataset
7
  import difflib
8
  import openai
9
  from typing import List
10
- import streamlit as st
11
- from streamlit_chat import message
12
- from streamlit_extras.colored_header import colored_header
13
- from streamlit_extras.add_vertical_space import add_vertical_space
14
 
15
  # Setup
16
 
@@ -523,14 +520,9 @@ 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!
@@ -538,36 +530,31 @@ with gr.Blocks(
538
  Ask anything about **TechSpark staff, tools, courses or location of tools**
539
  This assistant is powered by **OpenAI's GPT model** via `smolagents`, accessing accurate information from our curated dataset verified by techspark staff! """
540
  )
 
 
541
 
542
- # --- Chat interface ---
543
-
544
-
545
-
546
- chat = gr.Chatbot(label="TechSpark Assistant", height=450)
547
- inp = gr.Textbox(
548
- placeholder="Type your question here...",
549
- label="Your question",
550
- interactive=True
551
- )
552
  def respond(message, history):
553
  try:
 
554
  out = str(agent.run(message))
555
  except Exception as e:
556
  out = f"[Error] {e}"
 
 
557
  history = (history or []) + [(message, out)]
558
  return "", history
559
-
560
  gr.Examples(
 
561
  examples=[
562
  "Who is Ed?",
563
- "Who should I talk to for building a wooden table?",
564
- "How to access the laser cutter?"
565
  ],
566
- fn=respond,
567
- inputs=[inp],
568
- outputs=[chat]
569
  )
570
- # --- Connect input to chat ---
571
  inp.submit(respond, [inp, chat], [inp, chat])
572
 
573
  # Launch the demo
 
7
  import difflib
8
  import openai
9
  from typing import List
10
+
 
 
 
11
 
12
  # Setup
13
 
 
520
 
521
  import gradio as gr
522
 
523
+ # Minimal Gradio chat
524
+ with gr.Blocks(title="TechSpark Agent",theme= gr.themes.Soft() ) as demo:
525
+ gr.Markdown(
 
 
 
 
 
526
  """
527
  # 🤖 TechSpark AI Assistant
528
  Welcome to the TechSpark AI Assistant!
 
530
  Ask anything about **TechSpark staff, tools, courses or location of tools**
531
  This assistant is powered by **OpenAI's GPT model** via `smolagents`, accessing accurate information from our curated dataset verified by techspark staff! """
532
  )
533
+ chat = gr.Chatbot(height=420)
534
+ inp = gr.Textbox(placeholder="Ask your question in natural language.", label="Your question")
535
 
536
+ # No gr.State for agent — just close over `agent`
 
 
 
 
 
 
 
 
 
537
  def respond(message, history):
538
  try:
539
+ # 1. Use agent.chat() to maintain internal history
540
  out = str(agent.run(message))
541
  except Exception as e:
542
  out = f"[Error] {e}"
543
+
544
+ # This just updates the Gradio UI history
545
  history = (history or []) + [(message, out)]
546
  return "", history
547
+
548
  gr.Examples(
549
+ fn=respond,
550
  examples=[
551
  "Who is Ed?",
552
+ "Who to talk to to create a wooden table?",
553
+ "how to access laser cutter"
554
  ],
555
+ inputs=[inp]
 
 
556
  )
557
+
558
  inp.submit(respond, [inp, chat], [inp, chat])
559
 
560
  # Launch the demo