99load_dotenv ()
1010import autogen
1111import gradio as gr
12- import chainlit as cl
13- import asyncio
14- import uvicorn
15- from chainlit .cli import cli as chainlit_cli
16- from chainlit .server import app
1712import argparse
1813from .auto import AutoGenerator
1914from .agents_generator import AgentsGenerator
2015from .inbuilt_tools import *
2116
17+ try :
18+ from chainlit .cli import chainlit_run
19+ CHAINLIT_AVAILABLE = True
20+ except ImportError :
21+ CHAINLIT_AVAILABLE = False
22+
23+ try :
24+ import gradio as gr
25+ GRADIO_AVAILABLE = True
26+ except ImportError :
27+ GRADIO_AVAILABLE = False
28+
2229class PraisonAI :
2330 def __init__ (self , agent_file = "agents.yaml" , framework = "" , auto = False , init = False ):
2431 """
@@ -110,7 +117,10 @@ def main(self):
110117 elif args .ui == "chainlit" :
111118 self .create_chainlit_interface ()
112119 else :
113- self .create_chainlit_interface ()
120+ # Modify below code to allow default ui
121+ agents_generator = AgentsGenerator (self .agent_file , self .framework , self .config_list )
122+ result = agents_generator .generate_crew_and_kickoff ()
123+ return result
114124 else :
115125 agents_generator = AgentsGenerator (self .agent_file , self .framework , self .config_list )
116126 result = agents_generator .generate_crew_and_kickoff ()
@@ -135,7 +145,7 @@ def parse_args(self):
135145 """
136146 parser = argparse .ArgumentParser (prog = "praisonai" , description = "praisonAI command-line interface" )
137147 parser .add_argument ("--framework" , choices = ["crewai" , "autogen" ], help = "Specify the framework" )
138- parser .add_argument ("--ui" , nargs = '?' , const = ' chainlit' , default = "chainlit" , help = "Specify the UI framework (gradio or chainlit). Default chainlit " )
148+ parser .add_argument ("--ui" , choices = [ " chainlit" , "gradio" ] , help = "Specify the UI framework (gradio or chainlit)." )
139149 parser .add_argument ("--auto" , nargs = argparse .REMAINDER , help = "Enable auto mode and pass arguments for it" )
140150 parser .add_argument ("--init" , nargs = argparse .REMAINDER , help = "Enable auto mode and pass arguments for it" )
141151 parser .add_argument ("agent_file" , nargs = "?" , help = "Specify the agent file" )
@@ -165,40 +175,43 @@ def create_gradio_interface(self):
165175 Example:
166176 >>> praison_ai.create_gradio_interface()
167177 """
168- def generate_crew_and_kickoff_interface (auto_args , framework ):
169- """
170- Generate a crew and kick off tasks based on the provided auto arguments and framework.
171-
172- Args:
173- auto_args (list): Topic.
174- framework (str): The framework to use for generating agents.
175-
176- Returns:
177- str: A string representing the result of generating the crew and kicking off tasks.
178-
179- Raises:
180- None: This method does not raise any exceptions.
181-
182- Example:
183- >>> result = generate_crew_and_kickoff_interface("Create a movie about Cat in Mars", "crewai")
184- >>> print(result)
185- """
186- self .framework = framework
187- self .agent_file = "test.yaml"
188- generator = AutoGenerator (topic = auto_args , framework = self .framework )
189- self .agent_file = generator .generate ()
190- agents_generator = AgentsGenerator (self .agent_file , self .framework , self .config_list )
191- result = agents_generator .generate_crew_and_kickoff ()
192- return result
193-
194- gr .Interface (
195- fn = generate_crew_and_kickoff_interface ,
196- inputs = [gr .Textbox (lines = 2 , label = "Auto Args" ), gr .Dropdown (choices = ["crewai" , "autogen" ], label = "Framework" )],
197- outputs = "textbox" ,
198- title = "Praison AI Studio" ,
199- description = "Create Agents and perform tasks" ,
200- theme = "default"
201- ).launch ()
178+ if GRADIO_AVAILABLE :
179+ def generate_crew_and_kickoff_interface (auto_args , framework ):
180+ """
181+ Generate a crew and kick off tasks based on the provided auto arguments and framework.
182+
183+ Args:
184+ auto_args (list): Topic.
185+ framework (str): The framework to use for generating agents.
186+
187+ Returns:
188+ str: A string representing the result of generating the crew and kicking off tasks.
189+
190+ Raises:
191+ None: This method does not raise any exceptions.
192+
193+ Example:
194+ >>> result = generate_crew_and_kickoff_interface("Create a movie about Cat in Mars", "crewai")
195+ >>> print(result)
196+ """
197+ self .framework = framework
198+ self .agent_file = "test.yaml"
199+ generator = AutoGenerator (topic = auto_args , framework = self .framework )
200+ self .agent_file = generator .generate ()
201+ agents_generator = AgentsGenerator (self .agent_file , self .framework , self .config_list )
202+ result = agents_generator .generate_crew_and_kickoff ()
203+ return result
204+
205+ gr .Interface (
206+ fn = generate_crew_and_kickoff_interface ,
207+ inputs = [gr .Textbox (lines = 2 , label = "Auto Args" ), gr .Dropdown (choices = ["crewai" , "autogen" ], label = "Framework" )],
208+ outputs = "textbox" ,
209+ title = "Praison AI Studio" ,
210+ description = "Create Agents and perform tasks" ,
211+ theme = "default"
212+ ).launch ()
213+ else :
214+ print ("ERROR: Gradio is not installed. Please install it with 'pip install \" praisonai[gradio]\" ' to use this feature." )
202215
203216 def create_chainlit_interface (self ):
204217 """
@@ -211,10 +224,11 @@ def create_chainlit_interface(self):
211224 Returns:
212225 None: This function does not return any value. It starts the Chainlit application.
213226 """
214- from chainlit .cli import chainlit_run # Import chainlit_run
215- os .environ ["CHAINLIT_PORT" ] = "8082"
216- chainlit_run (["praisonai/chainlit_ui.py" ])
217-
227+ if CHAINLIT_AVAILABLE :
228+ os .environ ["CHAINLIT_PORT" ] = "8082"
229+ chainlit_run (["praisonai/chainlit_ui.py" ])
230+ else :
231+ print ("ERROR: Chainlit is not installed. Please install it with 'pip install \" praisonai\[ui]\" ' to use the UI." )
218232
219233if __name__ == "__main__" :
220234 praison_ai = PraisonAI ()
0 commit comments