Spaces:
Runtime error
Runtime error
alex-mindspace
commited on
Commit
Β·
a69441c
1
Parent(s):
bd51fa1
resetting the swarm regularly and completely
Browse files- gradio_app/interacton_with_swarm.py +3 -2
- gradio_app/interface.py +8 -2
- swarm_config.yaml +1 -1
- swarmai/Swarm.py +18 -0
gradio_app/interacton_with_swarm.py
CHANGED
@@ -218,5 +218,6 @@ def read_swarm_logs():
|
|
218 |
final_out = "Swarm is starting up..."
|
219 |
return final_out
|
220 |
|
221 |
-
def execute_swarm():
|
222 |
-
run_swarm()
|
|
|
|
218 |
final_out = "Swarm is starting up..."
|
219 |
return final_out
|
220 |
|
221 |
+
def execute_swarm(smarm_ui_status):
|
222 |
+
_ = run_swarm() # when it finishes, it will set SWARM_IS_RUNNING to False
|
223 |
+
smarm_ui_status = False #let's hope it's mutable
|
gradio_app/interface.py
CHANGED
@@ -32,16 +32,21 @@ def swarm_interface(swarm_role, swarm_global_goal, swarm_goals, n_managers, n_an
|
|
32 |
]
|
33 |
set_swarm_agents_config(agents_config)
|
34 |
|
35 |
-
t = threading.Thread(target=execute_swarm)
|
36 |
t.start()
|
37 |
-
print("Swarm is running")
|
38 |
SWARM_IS_RUNNING = True
|
|
|
39 |
|
40 |
def create_gradio_interface():
|
41 |
title = """
|
42 |
<h1 align="center">ππ Swarm Intelligence ππ</h1>
|
43 |
<div align="center">
|
44 |
<a style="display:inline-block" href='https://github.com/nicelir1996/GPT-Swarm'><img src='https://img.shields.io/github/stars/nicelir1996/GPT-Swarm?style=social' /></a>
|
|
|
|
|
|
|
|
|
|
|
45 |
<a href="https://huggingface.co/spaces/swarm-agents/swarm-agents?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
46 |
</div>
|
47 |
"""
|
@@ -95,6 +100,7 @@ def create_gradio_interface():
|
|
95 |
return display_logs(), display_output()
|
96 |
|
97 |
def submit_callback(swarm_role, swarm_global_goal, swarm_goals, n_managers, n_analysts, n_googlers):
|
|
|
98 |
if not SWARM_IS_RUNNING:
|
99 |
swarm_interface(swarm_role, swarm_global_goal, swarm_goals, n_managers, n_analysts, n_googlers)
|
100 |
return display_logs(), display_output()
|
|
|
32 |
]
|
33 |
set_swarm_agents_config(agents_config)
|
34 |
|
35 |
+
t = threading.Thread(target=execute_swarm, args=(SWARM_IS_RUNNING,))
|
36 |
t.start()
|
|
|
37 |
SWARM_IS_RUNNING = True
|
38 |
+
print(f"Swarm is running. SWARM_IS_RUNNING = {SWARM_IS_RUNNING}")
|
39 |
|
40 |
def create_gradio_interface():
|
41 |
title = """
|
42 |
<h1 align="center">ππ Swarm Intelligence ππ</h1>
|
43 |
<div align="center">
|
44 |
<a style="display:inline-block" href='https://github.com/nicelir1996/GPT-Swarm'><img src='https://img.shields.io/github/stars/nicelir1996/GPT-Swarm?style=social' /></a>
|
45 |
+
</div>
|
46 |
+
<br>
|
47 |
+
<div align="center">
|
48 |
+
β οΈβ οΈWe Highly recommend to use a duplicate space!β οΈβ οΈ
|
49 |
+
<br> Due to huggingface's API limitations, there can only be one instance of the swarm running at a time. You can see it's output, but your input will be ignored. The swarm resets every 10 minutes, so maybe you get lucky.
|
50 |
<a href="https://huggingface.co/spaces/swarm-agents/swarm-agents?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
51 |
</div>
|
52 |
"""
|
|
|
100 |
return display_logs(), display_output()
|
101 |
|
102 |
def submit_callback(swarm_role, swarm_global_goal, swarm_goals, n_managers, n_analysts, n_googlers):
|
103 |
+
print(f"Swarm is running. SWARM_IS_RUNNING = {SWARM_IS_RUNNING}")
|
104 |
if not SWARM_IS_RUNNING:
|
105 |
swarm_interface(swarm_role, swarm_global_goal, swarm_goals, n_managers, n_analysts, n_googlers)
|
106 |
return display_logs(), display_output()
|
swarm_config.yaml
CHANGED
@@ -7,7 +7,7 @@ swarm:
|
|
7 |
- n: 2
|
8 |
type: googler
|
9 |
run_dir: ./tmp/swarm
|
10 |
-
timeout_min:
|
11 |
task:
|
12 |
global_goal: A new startup just send us their pitch. Find if the startup is worth
|
13 |
investing in. The startup is called Brainamics and it is in the space of brain
|
|
|
7 |
- n: 2
|
8 |
type: googler
|
9 |
run_dir: ./tmp/swarm
|
10 |
+
timeout_min: 1
|
11 |
task:
|
12 |
global_goal: A new startup just send us their pitch. Find if the startup is worth
|
13 |
investing in. The startup is called Brainamics and it is in the space of brain
|
swarmai/Swarm.py
CHANGED
@@ -5,6 +5,7 @@ import yaml
|
|
5 |
import threading
|
6 |
import os
|
7 |
import json
|
|
|
8 |
|
9 |
from pathlib import Path
|
10 |
|
@@ -80,6 +81,16 @@ class Swarm:
|
|
80 |
self.output_file = str((self.data_dir / 'output.txt').resolve())
|
81 |
with open(self.output_file, 'w') as f:
|
82 |
f.write("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
# creating task queue
|
85 |
self.task_queue = PandasQueue(self.TASK_TYPES, self.WORKER_ROLES.keys(), self.TASK_ASSOCIATIONS)
|
@@ -153,6 +164,7 @@ class Swarm:
|
|
153 |
self.stop()
|
154 |
|
155 |
self.log("All agents have finished their work")
|
|
|
156 |
|
157 |
def create_report_qa_task(self):
|
158 |
"""Creates a task that will be used to evaluate the report quality.
|
@@ -204,6 +216,12 @@ class Swarm:
|
|
204 |
self.timeout = config["swarm"]["timeout_min"]*60
|
205 |
|
206 |
self.data_dir = Path(".", config["swarm"]["run_dir"]).resolve()
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
self.data_dir.mkdir(parents=True, exist_ok=True)
|
208 |
|
209 |
# getting the tasks
|
|
|
5 |
import threading
|
6 |
import os
|
7 |
import json
|
8 |
+
import shutil
|
9 |
|
10 |
from pathlib import Path
|
11 |
|
|
|
81 |
self.output_file = str((self.data_dir / 'output.txt').resolve())
|
82 |
with open(self.output_file, 'w') as f:
|
83 |
f.write("")
|
84 |
+
|
85 |
+
out_json = Path(str(self.output_file).replace(".txt", ".json"))
|
86 |
+
if out_json.exists():
|
87 |
+
with open(self.output_file, 'w') as f:
|
88 |
+
f.write("")
|
89 |
+
|
90 |
+
out_pretty = Path(str(self.output_file).replace(".txt", "_pretty.txt"))
|
91 |
+
if out_pretty.exists():
|
92 |
+
with open(self.output_file, 'w') as f:
|
93 |
+
f.write("")
|
94 |
|
95 |
# creating task queue
|
96 |
self.task_queue = PandasQueue(self.TASK_TYPES, self.WORKER_ROLES.keys(), self.TASK_ASSOCIATIONS)
|
|
|
164 |
self.stop()
|
165 |
|
166 |
self.log("All agents have finished their work")
|
167 |
+
return True
|
168 |
|
169 |
def create_report_qa_task(self):
|
170 |
"""Creates a task that will be used to evaluate the report quality.
|
|
|
216 |
self.timeout = config["swarm"]["timeout_min"]*60
|
217 |
|
218 |
self.data_dir = Path(".", config["swarm"]["run_dir"]).resolve()
|
219 |
+
# first, try to delete the directory with all the data
|
220 |
+
try:
|
221 |
+
shutil.rmtree(self.data_dir)
|
222 |
+
except Exception:
|
223 |
+
pass
|
224 |
+
|
225 |
self.data_dir.mkdir(parents=True, exist_ok=True)
|
226 |
|
227 |
# getting the tasks
|