Spaces:
Sleeping
Sleeping
| from crewai import Agent, Task, Crew | |
| from langchain_openai import ChatOpenAI | |
| import gradio as gr | |
| import os | |
| # ===== API Key ===== | |
| os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY", "your_api_key_here") | |
| # ===== Shared LLM ===== | |
| llm = ChatOpenAI(model="gpt-4o-mini", temperature=0.7) | |
| # ===== Agents ===== | |
| strategist = Agent( | |
| role="Mission Strategist", | |
| goal="Create high-level fictional guerrilla mission strategies for a simulation game.", | |
| backstory="An experienced tactician specializing in unconventional strategy for fictional settings.", | |
| llm=llm | |
| ) | |
| logistician = Agent( | |
| role="Operations Logistician", | |
| goal="Plan resources, equipment, and support needed for the fictional mission.", | |
| backstory="Expert in resource management for simulated missions.", | |
| llm=llm | |
| ) | |
| scout = Agent( | |
| role="Field Scout", | |
| goal="Provide fictional reconnaissance details about the mission area.", | |
| backstory="A skilled recon character who gathers terrain intel in fictional worlds.", | |
| llm=llm | |
| ) | |
| # ===== Tasks ===== | |
| task1 = Task( | |
| description="Analyze the user's fictional mission request and outline a strategy.", | |
| expected_output="A concise, high-level fictional mission strategy in bullet points.", | |
| agent=strategist | |
| ) | |
| task2 = Task( | |
| description="Based on the strategy, list required resources and logistical steps.", | |
| expected_output="A detailed list of fictional resources, equipment, and logistics plan.", | |
| agent=logistician | |
| ) | |
| task3 = Task( | |
| description="Provide fictional terrain and environmental information to aid planning.", | |
| expected_output="A terrain report describing fictional environment, obstacles, and opportunities.", | |
| agent=scout | |
| ) | |
| # ===== Crew ===== | |
| crew = Crew(agents=[strategist, logistician, scout], tasks=[task1, task2, task3], verbose=True) | |
| # ===== Gradio Function ===== | |
| def run_mission_planner(mission_request): | |
| result = crew.kickoff(inputs={"input": mission_request}) | |
| return str(result) | |
| # ===== UI ===== | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# 🗺️ Fictional Guerrilla Mission Planner (CrewAI Demo)") | |
| mission_input = gr.Textbox(label="Enter your fictional mission scenario", lines=4) | |
| output_box = gr.Textbox(label="Generated Mission Plan") | |
| submit_btn = gr.Button("Generate Plan") | |
| submit_btn.click(run_mission_planner, inputs=mission_input, outputs=output_box) | |
| if __name__ == "__main__": | |
| demo.launch() | |