Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- swarm_editor.py +9 -0
- user_interface.py +29 -13
swarm_editor.py
CHANGED
|
@@ -41,4 +41,13 @@ class SwarmEditor:
|
|
| 41 |
)
|
| 42 |
context_variables.update(response.context_variables)
|
| 43 |
initial_input = response.messages[-1]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
return response
|
|
|
|
| 41 |
)
|
| 42 |
context_variables.update(response.context_variables)
|
| 43 |
initial_input = response.messages[-1]["content"]
|
| 44 |
+
return response
|
| 45 |
+
|
| 46 |
+
def run_single_agent(self, agent, initial_input):
|
| 47 |
+
response = self.swarm.run(
|
| 48 |
+
agent=agent,
|
| 49 |
+
messages=[{"role": "user", "content": initial_input}],
|
| 50 |
+
context_variables={},
|
| 51 |
+
max_turns=1
|
| 52 |
+
)
|
| 53 |
return response
|
user_interface.py
CHANGED
|
@@ -28,13 +28,19 @@ class UserInterface:
|
|
| 28 |
)
|
| 29 |
return scrape_status.get('markdown', 'No content scraped')
|
| 30 |
|
| 31 |
-
def update_agent(self, index, name,
|
| 32 |
-
self.swarm_editor.update_agent(index, name,
|
| 33 |
return f"Agent {index} updated"
|
| 34 |
|
| 35 |
-
def run_workflow(self, scraped_content):
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
def launch(self):
|
| 40 |
with gr.Blocks() as interface:
|
|
@@ -44,22 +50,32 @@ class UserInterface:
|
|
| 44 |
scrape_button = gr.Button("Scrape Website")
|
| 45 |
scraped_content = gr.Textbox(label="Scraped Content")
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
with agent_tabs:
|
| 50 |
for i, agent in enumerate(self.config['agents']):
|
| 51 |
-
with gr.Tab(f"Agent {i}"):
|
| 52 |
name = gr.Textbox(label="Name", value=agent['name'])
|
| 53 |
-
|
| 54 |
update_button = gr.Button(f"Update Agent {i}")
|
| 55 |
update_output = gr.Textbox(label="Update Status")
|
| 56 |
-
update_button.click(self.update_agent, inputs=[gr.Number(value=i, visible=False), name,
|
| 57 |
|
| 58 |
run_button = gr.Button("Run Workflow")
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
scrape_button.click(self.scrape_website, inputs=[url], outputs=[scraped_content])
|
| 62 |
-
run_button.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
interface.launch()
|
| 65 |
|
|
|
|
| 28 |
)
|
| 29 |
return scrape_status.get('markdown', 'No content scraped')
|
| 30 |
|
| 31 |
+
def update_agent(self, index, name, prompt):
|
| 32 |
+
self.swarm_editor.update_agent(index, name, prompt)
|
| 33 |
return f"Agent {index} updated"
|
| 34 |
|
| 35 |
+
def run_workflow(self, scraped_content, progress=gr.Progress()):
|
| 36 |
+
outputs = [""] * len(self.swarm_editor.agents)
|
| 37 |
+
for i, agent in enumerate(self.swarm_editor.agents):
|
| 38 |
+
progress(i / len(self.swarm_editor.agents), f"Running Agent {i}: {agent.name}")
|
| 39 |
+
response = self.swarm_editor.run_single_agent(agent, scraped_content)
|
| 40 |
+
outputs[i] = response.messages[-1]['content']
|
| 41 |
+
scraped_content = outputs[i]
|
| 42 |
+
yield outputs
|
| 43 |
+
progress(1.0, "Workflow complete")
|
| 44 |
|
| 45 |
def launch(self):
|
| 46 |
with gr.Blocks() as interface:
|
|
|
|
| 50 |
scrape_button = gr.Button("Scrape Website")
|
| 51 |
scraped_content = gr.Textbox(label="Scraped Content")
|
| 52 |
|
| 53 |
+
agent_config_tabs = gr.Tabs()
|
| 54 |
+
with agent_config_tabs:
|
|
|
|
| 55 |
for i, agent in enumerate(self.config['agents']):
|
| 56 |
+
with gr.Tab(f"Agent {i} Config"):
|
| 57 |
name = gr.Textbox(label="Name", value=agent['name'])
|
| 58 |
+
prompt = gr.Textbox(label="Prompt", value=agent['instructions'], lines=3)
|
| 59 |
update_button = gr.Button(f"Update Agent {i}")
|
| 60 |
update_output = gr.Textbox(label="Update Status")
|
| 61 |
+
update_button.click(self.update_agent, inputs=[gr.Number(value=i, visible=False), name, prompt], outputs=[update_output])
|
| 62 |
|
| 63 |
run_button = gr.Button("Run Workflow")
|
| 64 |
+
|
| 65 |
+
output_tabs = gr.Tabs()
|
| 66 |
+
output_components = []
|
| 67 |
+
with output_tabs:
|
| 68 |
+
for i, agent in enumerate(self.config['agents']):
|
| 69 |
+
with gr.Tab(f"Agent {i} Output"):
|
| 70 |
+
output = gr.Textbox(label=f"{agent['name']} Output", lines=10)
|
| 71 |
+
output_components.append(output)
|
| 72 |
|
| 73 |
scrape_button.click(self.scrape_website, inputs=[url], outputs=[scraped_content])
|
| 74 |
+
run_button.click(
|
| 75 |
+
self.run_workflow,
|
| 76 |
+
inputs=[scraped_content],
|
| 77 |
+
outputs=output_components
|
| 78 |
+
)
|
| 79 |
|
| 80 |
interface.launch()
|
| 81 |
|