Update app.py
Browse files
app.py
CHANGED
@@ -7,48 +7,12 @@ import queue
|
|
7 |
import threading
|
8 |
import os
|
9 |
|
10 |
-
analysis_text = """
|
11 |
-
Stage 1: Ground-Based Spin-Up and Launch Initiation
|
12 |
-
• Concept:
|
13 |
-
A large, energy‑efficient, electrically powered centrifuge is built on the ground. This “spin launcher” uses renewable energy (for example, solar‐assisted electricity) to accelerate a specially designed payload assembly along a rotating arm or in a long circular tunnel.
|
14 |
-
• Benefits:
|
15 |
-
Because most of the kinetic energy is imparted mechanically (rather than via chemical propellant), the system drastically reduces the need for traditional, polluting rocket propellants. This stage is also relatively low‑cost because the “engine” is essentially an electromagnetic drive rather than a rocket motor.
|
16 |
-
Stage 2: Controlled Payload Release and Orbital Injection
|
17 |
-
• Concept:
|
18 |
-
At a pre‑calculated high tangential velocity, the payload is released from the spin launcher. A very short, minimal‐burn liquid or electric thruster (if needed) “tunes” the trajectory so that the payload enters a stable, low‑Earth orbit.
|
19 |
-
• Benefits:
|
20 |
-
The primary acceleration is mechanical, so only a tiny amount of propellant is required for orbital insertion. This greatly cuts both cost and the environmental impact typically associated with rocket launches.
|
21 |
-
Stage 3: Autonomous On-Orbit Stabilization and Despinning
|
22 |
-
• Concept:
|
23 |
-
Once in orbit, the payload’s onboard guidance and control systems (such as small reaction control thrusters or a yo-yo de-spin mechanism) despin and stabilize the payload. Integrated sensors and attitude-control software adjust the payload’s orientation and gently circularize the orbit.
|
24 |
-
• Benefits:
|
25 |
-
Autonomous stabilization minimizes additional propellant use and prepares the payload for a safe, predictable rendezvous. The controlled despinning ensures that the payload’s docking adapter remains in the proper orientation for subsequent attachment.
|
26 |
-
Stage 4: Rendezvous and Docking with the Manned Vehicle
|
27 |
-
• Concept:
|
28 |
-
A separately launched or pre‑positioned manned spacecraft (or space station) maneuvers to intercept the payload. The payload is equipped with a dedicated docking adapter (for instance, a magnetic or mechanical latch system engineered for high-precision contact under low‑g conditions).
|
29 |
-
• Benefits:
|
30 |
-
This phase uses conventional low‑delta‑V maneuvers that are far less expensive than a full chemical orbital insertion burn. The docking system is designed to absorb minor mismatches in velocity or attitude, allowing the crew to safely “hook on” to the payload. This minimizes extra propellant usage during the rendezvous phase.
|
31 |
-
Stage 5: Integrated Mission Operations and Continued Space Activity
|
32 |
-
• Concept:
|
33 |
-
Once docked, the combined system—the manned vehicle with the attached spin-delivered payload—continues its mission. The payload might provide additional resources (such as extra fuel, scientific instruments, or habitat modules) that augment the manned vehicle’s capabilities.
|
34 |
-
• Benefits:
|
35 |
-
With the payload permanently attached, mission operations (such as orbital adjustments, inter-station transfers, or even on-orbit assembly of larger structures) proceed with enhanced capabilities. The system’s reliance on mechanical acceleration for the bulk of the launch cut both launch costs and the environmental footprint, leaving only minor orbital maneuvers to be performed with conventional thrusters.
|
36 |
-
Summary
|
37 |
-
This five-stage system marries a ground-based spin acceleration concept with in-space docking and integration to achieve a “propellant-light” method for delivering payloads into orbit. By using a spin launcher to achieve high velocity on the ground (Stage 1) and minimizing onboard chemical propellant (Stage 2), the payload is inserted into orbit economically and with reduced environmental impact. On-orbit stabilization (Stage 3) prepares it for rendezvous with a manned vehicle (Stage 4), after which the combined system carries out the mission (Stage 5).
|
38 |
-
"""
|
39 |
-
|
40 |
-
summary_txt = """
|
41 |
-
Summary
|
42 |
-
This five-stage system marries a ground-based spin acceleration concept with in-space docking and integration to achieve a “propellant-light” method for delivering payloads into orbit. By using a spin launcher to achieve high velocity on the ground (Stage 1) and minimizing onboard chemical propellant (Stage 2), the payload is inserted into orbit economically and with reduced environmental impact. On-orbit stabilization (Stage 3) prepares it for rendezvous with a manned vehicle (Stage 4), after which the combined system carries out the mission (Stage 5).
|
43 |
-
"""
|
44 |
-
|
45 |
class AgentMessageQueue:
|
46 |
def __init__(self):
|
47 |
self.message_queue = queue.Queue()
|
48 |
self.last_agent = None
|
49 |
|
50 |
def add_message(self, message: Dict):
|
51 |
-
print(f"Adding message to queue: {message}") # Debug print
|
52 |
self.message_queue.put(message)
|
53 |
|
54 |
def get_messages(self) -> List[Dict]:
|
@@ -57,15 +21,15 @@ class AgentMessageQueue:
|
|
57 |
messages.append(self.message_queue.get())
|
58 |
return messages
|
59 |
|
60 |
-
class
|
61 |
def __init__(self, api_key: str = None):
|
62 |
self.api_key = api_key
|
63 |
self.message_queue = AgentMessageQueue()
|
64 |
-
self.
|
65 |
-
self.
|
66 |
-
self.
|
67 |
self.current_agent = None
|
68 |
-
self.
|
69 |
|
70 |
def initialize_agents(self, topic: str):
|
71 |
if not self.api_key:
|
@@ -74,185 +38,87 @@ class ArticleCrew:
|
|
74 |
os.environ["OPENAI_API_KEY"] = self.api_key
|
75 |
llm = ChatOpenAI(temperature=0.7, model="gpt-4")
|
76 |
|
77 |
-
self.
|
78 |
-
role="
|
79 |
-
goal=f"
|
80 |
-
backstory="Expert
|
81 |
allow_delegation=False,
|
82 |
verbose=True,
|
83 |
llm=llm
|
84 |
)
|
85 |
|
86 |
-
self.
|
87 |
-
role="
|
88 |
-
goal=f"
|
89 |
-
backstory="
|
90 |
allow_delegation=False,
|
91 |
verbose=True,
|
92 |
llm=llm
|
93 |
)
|
94 |
|
95 |
-
self.
|
96 |
-
role="
|
97 |
-
goal="
|
98 |
-
backstory="
|
99 |
allow_delegation=False,
|
100 |
verbose=True,
|
101 |
llm=llm
|
102 |
)
|
103 |
|
104 |
def create_tasks(self, topic: str) -> List[Task]:
|
105 |
-
|
106 |
-
description=f"""
|
107 |
-
1.
|
108 |
-
2.
|
109 |
-
3.
|
110 |
-
4.
|
111 |
-
expected_output="A comprehensive
|
112 |
-
agent=self.
|
113 |
)
|
114 |
|
115 |
-
|
116 |
-
description="""
|
117 |
-
1.
|
118 |
-
2.
|
119 |
-
3.
|
120 |
-
4.
|
121 |
-
|
122 |
-
|
123 |
-
agent=self.writer
|
124 |
)
|
125 |
|
126 |
-
|
127 |
-
description="""
|
128 |
-
1.
|
129 |
-
2.
|
130 |
-
3.
|
131 |
-
4.
|
132 |
-
expected_output="A
|
133 |
-
agent=self.
|
134 |
)
|
135 |
|
136 |
-
return [
|
137 |
-
|
138 |
-
async def process_article(self, topic: str) -> Generator[List[Dict], None, None]:
|
139 |
-
def add_agent_messages(agent_name: str, tasks: str, emoji: str = "🤖"):
|
140 |
-
# Add agent header
|
141 |
-
self.message_queue.add_message({
|
142 |
-
"role": "assistant",
|
143 |
-
"content": agent_name,
|
144 |
-
"metadata": {"title": f"{emoji} {agent_name}"}
|
145 |
-
})
|
146 |
-
|
147 |
-
# Add task description
|
148 |
-
self.message_queue.add_message({
|
149 |
-
"role": "assistant",
|
150 |
-
"content": tasks,
|
151 |
-
"metadata": {"title": f"📋 Task for {agent_name}"}
|
152 |
-
})
|
153 |
-
|
154 |
-
def setup_next_agent(current_agent: str) -> None:
|
155 |
-
agent_sequence = {
|
156 |
-
"Content Planner": ("Content Writer", """1. Use the content plan to craft a compelling blog post
|
157 |
-
2. Incorporate SEO keywords naturally
|
158 |
-
3. Ensure sections/subtitles are properly named in an engaging manner
|
159 |
-
4. Create proper structure with introduction, body, and conclusion
|
160 |
-
5. Proofread for grammatical errors"""),
|
161 |
-
|
162 |
-
"Content Writer": ("Editor", """1. Review the article for clarity and coherence
|
163 |
-
2. Check for grammatical errors and typos
|
164 |
-
3. Ensure consistent tone and style
|
165 |
-
4. Verify proper formatting and structure""")
|
166 |
-
}
|
167 |
-
|
168 |
-
if current_agent in agent_sequence:
|
169 |
-
next_agent, tasks = agent_sequence[current_agent]
|
170 |
-
self.current_agent = next_agent
|
171 |
-
add_agent_messages(next_agent, tasks)
|
172 |
-
|
173 |
-
|
174 |
-
def task_callback(task_output) -> None:
|
175 |
-
print(f"Task callback received: {task_output}") # Debug print
|
176 |
-
|
177 |
-
# Extract content from raw output
|
178 |
-
raw_output = task_output.raw
|
179 |
-
if "## Final Answer:" in raw_output:
|
180 |
-
content = raw_output.split("## Final Answer:")[1].strip()
|
181 |
-
else:
|
182 |
-
content = raw_output.strip()
|
183 |
-
|
184 |
-
# Handle the output based on current agent
|
185 |
-
if self.current_agent == "Editor":
|
186 |
-
# Don't show editor's output with metadata
|
187 |
-
# Instead, show completion message and final article
|
188 |
-
self.message_queue.add_message({
|
189 |
-
"role": "assistant",
|
190 |
-
"content": "Final article is ready!",
|
191 |
-
"metadata": {"title": "📝 Final Article"}
|
192 |
-
})
|
193 |
-
|
194 |
-
# Convert common markdown patterns to Gradio-compatible markdown
|
195 |
-
formatted_content = content
|
196 |
-
# Ensure proper spacing for headers
|
197 |
-
formatted_content = formatted_content.replace("\n#", "\n\n#")
|
198 |
-
# Ensure proper spacing for lists
|
199 |
-
formatted_content = formatted_content.replace("\n-", "\n\n-")
|
200 |
-
formatted_content = formatted_content.replace("\n*", "\n\n*")
|
201 |
-
formatted_content = formatted_content.replace("\n1.", "\n\n1.")
|
202 |
-
# Ensure proper spacing for paragraphs
|
203 |
-
formatted_content = formatted_content.replace("\n\n\n", "\n\n")
|
204 |
-
|
205 |
-
# Add the final article content without metadata
|
206 |
-
self.message_queue.add_message({
|
207 |
-
"role": "assistant",
|
208 |
-
"content": formatted_content
|
209 |
-
})
|
210 |
-
else:
|
211 |
-
# For other agents, show their output with metadata
|
212 |
-
self.message_queue.add_message({
|
213 |
-
"role": "assistant",
|
214 |
-
"content": content,
|
215 |
-
"metadata": {"title": f"✨ Output from {self.current_agent}"}
|
216 |
-
})
|
217 |
-
# Setup next agent
|
218 |
-
setup_next_agent(self.current_agent)
|
219 |
-
|
220 |
-
def step_callback(output: Any) -> None:
|
221 |
-
print(f"Step callback received: {output}") # Debug print
|
222 |
-
# We'll only use step_callback for logging purposes now
|
223 |
-
pass
|
224 |
|
|
|
225 |
try:
|
226 |
self.initialize_agents(topic)
|
227 |
-
self.current_agent = "
|
228 |
|
229 |
-
# Start process
|
230 |
yield [{
|
231 |
"role": "assistant",
|
232 |
-
"content": "Starting work on your
|
233 |
"metadata": {"title": "🚀 Process Started"}
|
234 |
}]
|
235 |
|
236 |
-
# Initialize first agent
|
237 |
-
add_agent_messages("Content Planner",
|
238 |
-
"""1. Prioritize the latest trends, key players, and noteworthy news
|
239 |
-
2. Identify the target audience, considering their interests and pain points
|
240 |
-
3. Develop a detailed content outline including introduction, key points, and call to action
|
241 |
-
4. Include SEO keywords and relevant data or sources""")
|
242 |
-
|
243 |
crew = Crew(
|
244 |
-
agents=[self.
|
245 |
tasks=self.create_tasks(topic),
|
246 |
-
verbose=True
|
247 |
-
step_callback=step_callback,
|
248 |
-
task_callback=task_callback
|
249 |
)
|
250 |
|
251 |
def run_crew():
|
252 |
try:
|
253 |
crew.kickoff()
|
254 |
except Exception as e:
|
255 |
-
print(f"Error in crew execution: {str(e)}") # Debug print
|
256 |
self.message_queue.add_message({
|
257 |
"role": "assistant",
|
258 |
"content": f"An error occurred: {str(e)}",
|
@@ -265,27 +131,22 @@ class ArticleCrew:
|
|
265 |
while thread.is_alive() or not self.message_queue.message_queue.empty():
|
266 |
messages = self.message_queue.get_messages()
|
267 |
if messages:
|
268 |
-
print(f"Yielding messages: {messages}") # Debug print
|
269 |
yield messages
|
270 |
await asyncio.sleep(0.1)
|
271 |
-
|
272 |
except Exception as e:
|
273 |
-
print(f"Error in process_article: {str(e)}") # Debug print
|
274 |
yield [{
|
275 |
"role": "assistant",
|
276 |
"content": f"An error occurred: {str(e)}",
|
277 |
"metadata": {"title": "❌ Error"}
|
278 |
}]
|
279 |
|
280 |
-
# [Rest of the code remains the same]
|
281 |
-
|
282 |
|
283 |
def create_demo():
|
284 |
-
|
285 |
|
286 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
287 |
-
gr.Markdown("#
|
288 |
-
|
289 |
openai_api_key = gr.Textbox(
|
290 |
label='OpenAI API Key',
|
291 |
type='password',
|
@@ -294,26 +155,26 @@ def create_demo():
|
|
294 |
)
|
295 |
|
296 |
chatbot = gr.Chatbot(
|
297 |
-
label="
|
298 |
height=700,
|
299 |
type="messages",
|
300 |
show_label=True,
|
301 |
visible=False,
|
302 |
avatar_images=(None, "https://avatars.githubusercontent.com/u/170677839?v=4"),
|
303 |
-
render_markdown=True
|
304 |
)
|
305 |
|
306 |
with gr.Row(equal_height=True):
|
307 |
topic = gr.Textbox(
|
308 |
-
label="
|
309 |
-
placeholder="Enter
|
310 |
scale=4,
|
311 |
visible=False
|
312 |
)
|
313 |
-
btn = gr.Button("
|
314 |
|
315 |
async def process_input(topic, history, api_key):
|
316 |
-
nonlocal
|
317 |
if not api_key:
|
318 |
history = history or []
|
319 |
history.append({
|
@@ -324,15 +185,15 @@ def create_demo():
|
|
324 |
yield history
|
325 |
return
|
326 |
|
327 |
-
if
|
328 |
-
|
329 |
|
330 |
history = history or []
|
331 |
-
history.append({"role": "user", "content": f"
|
332 |
yield history
|
333 |
|
334 |
try:
|
335 |
-
async for messages in
|
336 |
history.extend(messages)
|
337 |
yield history
|
338 |
except Exception as e:
|
@@ -343,21 +204,12 @@ def create_demo():
|
|
343 |
})
|
344 |
yield history
|
345 |
|
346 |
-
|
347 |
-
return {
|
348 |
-
openai_api_key: gr.Textbox(visible=False),
|
349 |
-
chatbot: gr.Chatbot(visible=True),
|
350 |
-
topic: gr.Textbox(visible=True),
|
351 |
-
btn: gr.Button(visible=True)
|
352 |
-
}
|
353 |
-
|
354 |
-
openai_api_key.submit(show_interface, None, [openai_api_key, chatbot, topic, btn])
|
355 |
btn.click(process_input, [topic, chatbot, openai_api_key], [chatbot])
|
356 |
-
topic.submit(process_input, [topic, chatbot, openai_api_key], [chatbot])
|
357 |
|
358 |
return demo
|
359 |
|
360 |
if __name__ == "__main__":
|
361 |
demo = create_demo()
|
362 |
demo.queue()
|
363 |
-
demo.launch(debug=True)
|
|
|
7 |
import threading
|
8 |
import os
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
class AgentMessageQueue:
|
11 |
def __init__(self):
|
12 |
self.message_queue = queue.Queue()
|
13 |
self.last_agent = None
|
14 |
|
15 |
def add_message(self, message: Dict):
|
|
|
16 |
self.message_queue.put(message)
|
17 |
|
18 |
def get_messages(self) -> List[Dict]:
|
|
|
21 |
messages.append(self.message_queue.get())
|
22 |
return messages
|
23 |
|
24 |
+
class SpaceSystemCrew:
|
25 |
def __init__(self, api_key: str = None):
|
26 |
self.api_key = api_key
|
27 |
self.message_queue = AgentMessageQueue()
|
28 |
+
self.system_architect = None
|
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:
|
|
|
38 |
os.environ["OPENAI_API_KEY"] = self.api_key
|
39 |
llm = ChatOpenAI(temperature=0.7, model="gpt-4")
|
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
|
48 |
)
|
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,
|
56 |
llm=llm
|
57 |
)
|
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 |
|
118 |
def run_crew():
|
119 |
try:
|
120 |
crew.kickoff()
|
121 |
except Exception as e:
|
|
|
122 |
self.message_queue.add_message({
|
123 |
"role": "assistant",
|
124 |
"content": f"An error occurred: {str(e)}",
|
|
|
131 |
while thread.is_alive() or not self.message_queue.message_queue.empty():
|
132 |
messages = self.message_queue.get_messages()
|
133 |
if messages:
|
|
|
134 |
yield messages
|
135 |
await asyncio.sleep(0.1)
|
|
|
136 |
except Exception as e:
|
|
|
137 |
yield [{
|
138 |
"role": "assistant",
|
139 |
"content": f"An error occurred: {str(e)}",
|
140 |
"metadata": {"title": "❌ Error"}
|
141 |
}]
|
142 |
|
|
|
|
|
143 |
|
144 |
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',
|
152 |
type='password',
|
|
|
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({
|
|
|
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:
|
|
|
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 |
|
212 |
if __name__ == "__main__":
|
213 |
demo = create_demo()
|
214 |
demo.queue()
|
215 |
+
demo.launch(debug=True)
|