Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -740,29 +740,42 @@ agent = smolagents.CodeAgent(
|
|
| 740 |
verbosity_level=2, # show steps in logs for class demo
|
| 741 |
)
|
| 742 |
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 753 |
|
| 754 |
-
|
| 755 |
-
|
|
|
|
|
|
|
| 756 |
|
| 757 |
-
|
|
|
|
|
|
|
|
|
|
| 758 |
|
| 759 |
-
|
| 760 |
-
|
| 761 |
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
inp.submit(respond, [inp, chat], [inp, chat])
|
| 766 |
|
| 767 |
gr.Examples(
|
| 768 |
examples=[
|
|
@@ -777,4 +790,6 @@ with gr.Blocks() as demo:
|
|
| 777 |
cache_examples=False,
|
| 778 |
)
|
| 779 |
|
|
|
|
|
|
|
| 780 |
demo.launch()
|
|
|
|
| 740 |
verbosity_level=2, # show steps in logs for class demo
|
| 741 |
)
|
| 742 |
|
| 743 |
+
|
| 744 |
+
# Centered title and description using HTML
|
| 745 |
+
gr.HTML("""
|
| 746 |
+
<div style="text-align: center; font-family: 'Arial', sans-serif;">
|
| 747 |
+
<h1 style="color:#1f77b4; margin-bottom: 20px; font-weight: 300;">
|
| 748 |
+
🤖 TechSpark AI Assistant
|
| 749 |
+
</h1>
|
| 750 |
+
|
| 751 |
+
<p style="margin-top: 0; font-weight: 300; font-size: 16px; color:#555;">
|
| 752 |
+
Welcome to the TechSpark AI Assistant!<br>
|
| 753 |
+
Ask anything about TechSpark staff, tools, courses or location of tools.<br>
|
| 754 |
+
This assistant is powered by OpenAI's GPT model via smolagents,
|
| 755 |
+
accessing accurate information from our curated dataset verified by TechSpark staff!
|
| 756 |
+
</p>
|
| 757 |
+
</div>
|
| 758 |
+
""")
|
| 759 |
+
|
| 760 |
+
# IMPORTANT: no `type="messages"` here
|
| 761 |
+
chat = gr.Chatbot(height=420)
|
| 762 |
+
inp = gr.Textbox(placeholder="Ask your question in natural language.", label="Your question")
|
| 763 |
|
| 764 |
+
def respond(message, history):
|
| 765 |
+
# history is what goes into the Chatbot component
|
| 766 |
+
if history is None:
|
| 767 |
+
history = []
|
| 768 |
|
| 769 |
+
try:
|
| 770 |
+
out = str(agent.run(message))
|
| 771 |
+
except Exception as e:
|
| 772 |
+
out = f"[Error] {e}"
|
| 773 |
|
| 774 |
+
# For your Gradio version, history must be a list of [user, assistant] lists
|
| 775 |
+
history.append([message, out])
|
| 776 |
|
| 777 |
+
# Clear the input box, update chat
|
| 778 |
+
return "", history
|
|
|
|
|
|
|
| 779 |
|
| 780 |
gr.Examples(
|
| 781 |
examples=[
|
|
|
|
| 790 |
cache_examples=False,
|
| 791 |
)
|
| 792 |
|
| 793 |
+
inp.submit(respond, [inp, chat], [inp, chat])
|
| 794 |
+
|
| 795 |
demo.launch()
|