Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 771 |
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,
|
| 787 |
)
|
| 788 |
|
| 789 |
-
|
| 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()
|
|
|
|
|
|