Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,8 +10,7 @@ from retriever import load_guest_dataset
|
|
| 10 |
# Constants
|
| 11 |
SAMPLE_FILE = "sample_guests.csv"
|
| 12 |
|
| 13 |
-
# Generate sample dataset
|
| 14 |
-
|
| 15 |
def generate_sample_guest_csv():
|
| 16 |
if not os.path.exists(SAMPLE_FILE):
|
| 17 |
guest_dataset = datasets.load_dataset("agents-course/unit3-invitees", split="train")
|
|
@@ -68,12 +67,18 @@ with gr.Blocks() as demo:
|
|
| 68 |
gr.Markdown("Powered by **smolagents**")
|
| 69 |
|
| 70 |
with gr.Column(scale=3):
|
| 71 |
-
output = gr.Chatbot(label="Agent")
|
| 72 |
|
| 73 |
def run_query(prompt, file):
|
| 74 |
global agent_instance
|
| 75 |
agent_instance = build_agent(file_path=file)
|
| 76 |
result = agent_instance.run(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
return [("User", prompt), ("Agent", result)]
|
| 78 |
|
| 79 |
submit.click(fn=run_query, inputs=[prompt, guest_file], outputs=output)
|
|
|
|
| 10 |
# Constants
|
| 11 |
SAMPLE_FILE = "sample_guests.csv"
|
| 12 |
|
| 13 |
+
# Generate sample dataset if not already present
|
|
|
|
| 14 |
def generate_sample_guest_csv():
|
| 15 |
if not os.path.exists(SAMPLE_FILE):
|
| 16 |
guest_dataset = datasets.load_dataset("agents-course/unit3-invitees", split="train")
|
|
|
|
| 67 |
gr.Markdown("Powered by **smolagents**")
|
| 68 |
|
| 69 |
with gr.Column(scale=3):
|
| 70 |
+
output = gr.Chatbot(label="Agent") # default format (list of tuples)
|
| 71 |
|
| 72 |
def run_query(prompt, file):
|
| 73 |
global agent_instance
|
| 74 |
agent_instance = build_agent(file_path=file)
|
| 75 |
result = agent_instance.run(prompt)
|
| 76 |
+
|
| 77 |
+
# Ensure result is string for chatbot format
|
| 78 |
+
if isinstance(result, dict):
|
| 79 |
+
# Convert dict to readable string if agent returns JSON-like structure
|
| 80 |
+
result = "\n\n".join(f"**{k}**: {v}" for k, v in result.items())
|
| 81 |
+
|
| 82 |
return [("User", prompt), ("Agent", result)]
|
| 83 |
|
| 84 |
submit.click(fn=run_query, inputs=[prompt, guest_file], outputs=output)
|