Spaces:
Runtime error
Runtime error
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384import osimport gradio as grfrom crewai import Agent, Task, Crew, Processfrom crewai_tools import SerperDevToolfrom langchain_groq import ChatGroq
# Set up environment variablesos.environ["GROQ_API_KEY"] = "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"os.environ["SERPER_API_KEY"] = "206256c6acfbcd5a46195f3312aaa7e8ed38ae5f"
# Initialize Groq LLMgroq_llm = ChatGroq( model_name="mixtral-8x7b-32768", temperature=0.7, max_tokens=32768)
# Initialize search toolsearch_tool = SerperDevTool()
# Define agentsresearcher = Agent( role='Senior Research Analyst', goal='Uncover cutting-edge developments in AI and data science', backstory="""You work at a leading tech think tank. Your expertise lies in identifying emerging trends. You have a knack for dissecting complex data and presenting actionable insights.""", verbose=True, allow_delegation=False, llm=groq_llm, tools=[search_tool])
writer = Agent( role='Tech Content Strategist', goal='Craft compelling content on tech advancements', backstory="""You are a renowned Content Strategist, known for your insightful and engaging articles. You transform complex concepts into compelling narratives.""", verbose=True, allow_delegation=True, llm=groq_llm)
def run_agents(research_topic): # Create tasks task1 = Task( description=f"""Conduct a comprehensive analysis of the latest advancements in {research_topic} in 2024. Identify key trends, breakthrough technologies, and potential industry impacts.""", expected_output="Full analysis report in bullet points", agent=researcher )
task2 = Task( description="""Using the insights provided, develop an engaging blog post that highlights the most significant advancements. Your post should be informative yet accessible, catering to a tech-savvy audience. Make it sound cool, avoid complex words so it doesn't sound like AI.""", expected_output="Full blog post of at least 4 paragraphs", agent=writer )
# Instantiate crew crew = Crew( agents=[researcher, writer], tasks=[task1, task2], verbose=2, process=Process.sequential )
# Run the crew result = crew.kickoff() return result
# Define Gradio interfaceiface = gr.Interface( fn=run_agents, inputs=gr.Textbox(label="Enter a research topic (e.g., 'AI', 'Machine Learning', 'Data Science')"), outputs=gr.Textbox(label="Results"), title="AI Research and Blog Post Generator", description="Enter a research topic to generate an analysis and blog post about recent advancements.")
# Launch the Gradio interfaceiface.launch()app.pyAdded+84