Update app.py
Browse files
app.py
CHANGED
@@ -29,9 +29,9 @@ class SpaceSystemCrew:
|
|
29 |
self.mechanical_engineer = None
|
30 |
self.aerospace_manager = None
|
31 |
self.current_agent = None
|
32 |
-
self.
|
33 |
|
34 |
-
def initialize_agents(self,
|
35 |
if not self.api_key:
|
36 |
raise ValueError("OpenAI API key is required")
|
37 |
|
@@ -40,8 +40,8 @@ class SpaceSystemCrew:
|
|
40 |
|
41 |
self.system_architect = Agent(
|
42 |
role="System Architect",
|
43 |
-
goal=f"
|
44 |
-
backstory="Expert in space system design,
|
45 |
allow_delegation=False,
|
46 |
verbose=True,
|
47 |
llm=llm
|
@@ -49,7 +49,7 @@ class SpaceSystemCrew:
|
|
49 |
|
50 |
self.mechanical_engineer = Agent(
|
51 |
role="Mechanical Engineer",
|
52 |
-
goal=f"
|
53 |
backstory="Specialist in high-velocity launch systems and orbital stabilization",
|
54 |
allow_delegation=False,
|
55 |
verbose=True,
|
@@ -58,60 +58,57 @@ class SpaceSystemCrew:
|
|
58 |
|
59 |
self.aerospace_manager = Agent(
|
60 |
role="Aerospace Mission Manager",
|
61 |
-
goal=f"Ensure mission feasibility
|
62 |
backstory="Oversees project feasibility, mission planning, and ensures integration with existing aerospace infrastructure",
|
63 |
allow_delegation=False,
|
64 |
verbose=True,
|
65 |
llm=llm
|
66 |
)
|
67 |
|
68 |
-
def create_tasks(self,
|
69 |
architect_task = Task(
|
70 |
-
description=f"""
|
71 |
-
1.
|
72 |
-
2.
|
73 |
-
3.
|
74 |
-
|
75 |
-
expected_output="A comprehensive space system architecture plan",
|
76 |
agent=self.system_architect
|
77 |
)
|
78 |
|
79 |
mechanical_task = Task(
|
80 |
-
description="""
|
81 |
-
1.
|
82 |
-
2.
|
83 |
-
3.
|
84 |
-
|
85 |
-
expected_output="Detailed propulsion and structural design specifications",
|
86 |
agent=self.mechanical_engineer
|
87 |
)
|
88 |
|
89 |
aerospace_task = Task(
|
90 |
-
description="""
|
91 |
-
1.
|
92 |
-
2. Safety
|
93 |
-
3.
|
94 |
-
|
95 |
-
expected_output="A validated mission feasibility and execution plan",
|
96 |
agent=self.aerospace_manager
|
97 |
)
|
98 |
|
99 |
return [architect_task, mechanical_task, aerospace_task]
|
100 |
|
101 |
-
async def process_design(self,
|
102 |
try:
|
103 |
-
self.initialize_agents(
|
104 |
self.current_agent = "System Architect"
|
105 |
|
106 |
yield [{
|
107 |
"role": "assistant",
|
108 |
-
"content": "Starting
|
109 |
"metadata": {"title": "π Process Started"}
|
110 |
}]
|
111 |
|
112 |
crew = Crew(
|
113 |
agents=[self.system_architect, self.mechanical_engineer, self.aerospace_manager],
|
114 |
-
tasks=self.create_tasks(
|
115 |
verbose=True
|
116 |
)
|
117 |
|
@@ -133,6 +130,11 @@ class SpaceSystemCrew:
|
|
133 |
if messages:
|
134 |
yield messages
|
135 |
await asyncio.sleep(0.1)
|
|
|
|
|
|
|
|
|
|
|
136 |
except Exception as e:
|
137 |
yield [{
|
138 |
"role": "assistant",
|
@@ -145,7 +147,7 @@ def create_demo():
|
|
145 |
space_crew = None
|
146 |
|
147 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
148 |
-
gr.Markdown("# π AI Space System
|
149 |
|
150 |
openai_api_key = gr.Textbox(
|
151 |
label='OpenAI API Key',
|
@@ -154,58 +156,27 @@ def create_demo():
|
|
154 |
interactive=True
|
155 |
)
|
156 |
|
157 |
-
|
158 |
-
label="
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
visible=False,
|
163 |
-
avatar_images=(None, "https://avatars.githubusercontent.com/u/170677839?v=4"),
|
164 |
-
render_markdown=True
|
165 |
)
|
166 |
|
167 |
-
|
168 |
-
topic = gr.Textbox(
|
169 |
-
label="Space System Name",
|
170 |
-
placeholder="Enter system name...",
|
171 |
-
scale=4,
|
172 |
-
visible=False
|
173 |
-
)
|
174 |
-
btn = gr.Button("Design System", variant="primary", scale=1, visible=False)
|
175 |
|
176 |
-
async def process_input(
|
177 |
nonlocal space_crew
|
178 |
if not api_key:
|
179 |
-
|
180 |
-
history.append({
|
181 |
-
"role": "assistant",
|
182 |
-
"content": "Please provide an OpenAI API key.",
|
183 |
-
"metadata": {"title": "β Error"}
|
184 |
-
})
|
185 |
-
yield history
|
186 |
-
return
|
187 |
|
188 |
if space_crew is None:
|
189 |
space_crew = SpaceSystemCrew(api_key=api_key)
|
190 |
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
try:
|
196 |
-
async for messages in space_crew.process_design(topic):
|
197 |
-
history.extend(messages)
|
198 |
-
yield history
|
199 |
-
except Exception as e:
|
200 |
-
history.append({
|
201 |
-
"role": "assistant",
|
202 |
-
"content": f"An error occurred: {str(e)}",
|
203 |
-
"metadata": {"title": "β Error"}
|
204 |
-
})
|
205 |
-
yield history
|
206 |
-
|
207 |
-
openai_api_key.submit(lambda: {openai_api_key: gr.Textbox(visible=False), chatbot: gr.Chatbot(visible=True), topic: gr.Textbox(visible=True), btn: gr.Button(visible=True)}, None, [openai_api_key, chatbot, topic, btn])
|
208 |
-
btn.click(process_input, [topic, chatbot, openai_api_key], [chatbot])
|
209 |
|
210 |
return demo
|
211 |
|
|
|
29 |
self.mechanical_engineer = None
|
30 |
self.aerospace_manager = None
|
31 |
self.current_agent = None
|
32 |
+
self.final_refined_text = None
|
33 |
|
34 |
+
def initialize_agents(self, space_system_description: str):
|
35 |
if not self.api_key:
|
36 |
raise ValueError("OpenAI API key is required")
|
37 |
|
|
|
40 |
|
41 |
self.system_architect = Agent(
|
42 |
role="System Architect",
|
43 |
+
goal=f"Analyze and refine the space system concept based on the provided description",
|
44 |
+
backstory="Expert in space system design, ensuring logical consistency and feasibility",
|
45 |
allow_delegation=False,
|
46 |
verbose=True,
|
47 |
llm=llm
|
|
|
49 |
|
50 |
self.mechanical_engineer = Agent(
|
51 |
role="Mechanical Engineer",
|
52 |
+
goal=f"Refine structural and propulsion mechanisms based on the provided description",
|
53 |
backstory="Specialist in high-velocity launch systems and orbital stabilization",
|
54 |
allow_delegation=False,
|
55 |
verbose=True,
|
|
|
58 |
|
59 |
self.aerospace_manager = Agent(
|
60 |
role="Aerospace Mission Manager",
|
61 |
+
goal=f"Ensure mission feasibility and refine execution details based on the provided description",
|
62 |
backstory="Oversees project feasibility, mission planning, and ensures integration with existing aerospace infrastructure",
|
63 |
allow_delegation=False,
|
64 |
verbose=True,
|
65 |
llm=llm
|
66 |
)
|
67 |
|
68 |
+
def create_tasks(self, space_system_description: str) -> List[Task]:
|
69 |
architect_task = Task(
|
70 |
+
description=f"""Analyze and refine the provided space system concept, ensuring:
|
71 |
+
1. Logical consistency and feasibility
|
72 |
+
2. Integration with existing space infrastructure
|
73 |
+
3. Improved clarity and technical accuracy""",
|
74 |
+
expected_output="A refined version of the space system concept",
|
|
|
75 |
agent=self.system_architect
|
76 |
)
|
77 |
|
78 |
mechanical_task = Task(
|
79 |
+
description="""Enhance the structural and propulsion aspects described in the provided description, including:
|
80 |
+
1. Refining spin-launcher specifications
|
81 |
+
2. Optimizing payload stabilization and orbital insertion methods
|
82 |
+
3. Ensuring energy efficiency and mechanical reliability""",
|
83 |
+
expected_output="Refined propulsion and structural details",
|
|
|
84 |
agent=self.mechanical_engineer
|
85 |
)
|
86 |
|
87 |
aerospace_task = Task(
|
88 |
+
description="""Evaluate and refine mission execution strategies based on the provided description, ensuring:
|
89 |
+
1. Practical feasibility of launch and docking operations
|
90 |
+
2. Safety enhancements and risk mitigation measures
|
91 |
+
3. Seamless operational procedures for post-docking activities""",
|
92 |
+
expected_output="A refined mission feasibility and execution plan",
|
|
|
93 |
agent=self.aerospace_manager
|
94 |
)
|
95 |
|
96 |
return [architect_task, mechanical_task, aerospace_task]
|
97 |
|
98 |
+
async def process_design(self, space_system_description: str) -> Generator[List[Dict], None, None]:
|
99 |
try:
|
100 |
+
self.initialize_agents(space_system_description)
|
101 |
self.current_agent = "System Architect"
|
102 |
|
103 |
yield [{
|
104 |
"role": "assistant",
|
105 |
+
"content": "Starting analysis and refinement of the space system...",
|
106 |
"metadata": {"title": "π Process Started"}
|
107 |
}]
|
108 |
|
109 |
crew = Crew(
|
110 |
agents=[self.system_architect, self.mechanical_engineer, self.aerospace_manager],
|
111 |
+
tasks=self.create_tasks(space_system_description),
|
112 |
verbose=True
|
113 |
)
|
114 |
|
|
|
130 |
if messages:
|
131 |
yield messages
|
132 |
await asyncio.sleep(0.1)
|
133 |
+
|
134 |
+
self.final_refined_text = "\n\n".join([msg["content"] for msg in self.message_queue.get_messages() if msg["role"] == "assistant"])
|
135 |
+
print("Final Refined Space System Design:")
|
136 |
+
print(self.final_refined_text)
|
137 |
+
|
138 |
except Exception as e:
|
139 |
yield [{
|
140 |
"role": "assistant",
|
|
|
147 |
space_crew = None
|
148 |
|
149 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
150 |
+
gr.Markdown("# π AI Space System Refinement Crew")
|
151 |
|
152 |
openai_api_key = gr.Textbox(
|
153 |
label='OpenAI API Key',
|
|
|
156 |
interactive=True
|
157 |
)
|
158 |
|
159 |
+
space_system_description = gr.Textbox(
|
160 |
+
label="Space System Description",
|
161 |
+
placeholder="Enter space system details...",
|
162 |
+
lines=10,
|
163 |
+
interactive=True
|
|
|
|
|
|
|
164 |
)
|
165 |
|
166 |
+
btn = gr.Button("Refine System", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
|
168 |
+
async def process_input(space_system_description, history, api_key):
|
169 |
nonlocal space_crew
|
170 |
if not api_key:
|
171 |
+
return [{"role": "assistant", "content": "Please provide an OpenAI API key."}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
if space_crew is None:
|
174 |
space_crew = SpaceSystemCrew(api_key=api_key)
|
175 |
|
176 |
+
async for messages in space_crew.process_design(space_system_description):
|
177 |
+
yield messages
|
178 |
+
|
179 |
+
btn.click(process_input, [space_system_description, openai_api_key], [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
|
181 |
return demo
|
182 |
|