eaglelandsonce commited on
Commit
a29567e
Β·
verified Β·
1 Parent(s): 2819b0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -73
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.final_design = None
33
 
34
- def initialize_agents(self, topic: str):
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"Design the architecture of the {topic} space system",
44
- backstory="Expert in space system design, integrating mechanical and propulsion components into a cohesive system",
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"Develop structural and propulsion mechanisms for {topic}",
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, safety, and execution for {topic}",
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, topic: str) -> List[Task]:
69
  architect_task = Task(
70
- description=f"""Develop the complete architecture for the {topic} space system, including:
71
- 1. High-level design of the five-stage system
72
- 2. Identification of key components and subsystems
73
- 3. Integration with existing space infrastructure
74
- 4. Energy efficiency and sustainability considerations""",
75
- expected_output="A comprehensive space system architecture plan",
76
  agent=self.system_architect
77
  )
78
 
79
  mechanical_task = Task(
80
- description="""Design the structural and propulsion aspects of the space system, including:
81
- 1. Engineering specifications for the spin-launcher mechanism
82
- 2. Payload stabilization and orbital insertion strategies
83
- 3. Material selection and thermal considerations
84
- 4. Fuel efficiency and mechanical reliability""",
85
- expected_output="Detailed propulsion and structural design specifications",
86
  agent=self.mechanical_engineer
87
  )
88
 
89
  aerospace_task = Task(
90
- description="""Assess the feasibility and mission execution strategies, including:
91
- 1. Launch site selection and environmental impact assessment
92
- 2. Safety protocols and risk mitigation strategies
93
- 3. Crew and payload rendezvous procedures
94
- 4. Operational procedures for space missions post-docking""",
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, topic: str) -> Generator[List[Dict], None, None]:
102
  try:
103
- self.initialize_agents(topic)
104
  self.current_agent = "System Architect"
105
 
106
  yield [{
107
  "role": "assistant",
108
- "content": "Starting work on your space system design...",
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(topic),
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 Design Crew")
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
- chatbot = gr.Chatbot(
158
- label="Design Process",
159
- height=700,
160
- type="messages",
161
- show_label=True,
162
- visible=False,
163
- avatar_images=(None, "https://avatars.githubusercontent.com/u/170677839?v=4"),
164
- render_markdown=True
165
  )
166
 
167
- with gr.Row(equal_height=True):
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(topic, history, api_key):
177
  nonlocal space_crew
178
  if not api_key:
179
- history = history or []
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
- history = history or []
192
- history.append({"role": "user", "content": f"Design a space system for: {topic}"})
193
- yield history
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