from crewai import Agent, Task, Crew, LLM import gradio as gr import os def create_crew(topic): """Creates a CrewAI team with specialized agents for any research topic.""" llm_model = LLM(model="groq/llama-3.3-70b-versatile") # Researcher Agent researcher = Agent( role="Researcher", goal=f"Gather comprehensive and accurate information on the topic: {topic}.", backstory="An expert in data collection, analysis, and extracting insights from various sources.", llm=llm_model ) # Writer Agent writer = Agent( role="Writer", goal="Summarize research findings into a well-structured and coherent report.", backstory="A seasoned writer with expertise in transforming raw information into clear and concise text.", llm=llm_model ) # LaTeX Document Creator Agent latex_creator = Agent( role="LaTeX Document Creator", goal="Convert the summarized report into a well-formatted LaTeX document.", backstory="A skilled document formatter who ensures professional presentation in LaTeX.", llm=llm_model ) # Research Task research_task = Task( description=f"Conduct in-depth research on {topic}.", agent=researcher, expected_output=f'Detailed and accurate information on {topic}.' ) # Writing Task writing_task = Task( description="Based on the research findings, generate a concise and well-structured summary.", agent=writer, expected_output='A clear and structured summary of the research findings.' ) # LaTeX Document Creation Task latex_task = Task( description="Transform the research summary into a properly formatted LaTeX document.", agent=latex_creator, expected_output='A LaTeX document containing the summarized research.' ) # Assemble the Crew crew_team = Crew( agents=[researcher, writer, latex_creator], tasks=[research_task, writing_task, latex_task] ) return crew_team def execute_crew(input_text): """Executes the CrewAI workflow for the given topic.""" print("Executing CrewAI with input:", input_text) crew_team = create_crew(input_text) result = crew_team.kickoff() print("CrewAI Output:", result) return result # Gradio Interface interface = gr.Interface( fn=execute_crew, inputs=gr.Text(value="Enter a topic for research", interactive=True, placeholder="e.g., Quantum Computing"), outputs="text", title="Crew AI - Research and LaTeX Report Generator", description="Enter any topic, and the AI team will research and generate a LaTeX report based on it." ) if __name__ == "__main__": interface.launch()