Spaces:
Sleeping
Sleeping
import os | |
import gradio as gr | |
from crewai import Agent, Task, Crew, Process | |
from crewai_tools import SerperDevTool | |
from langchain_groq import ChatGroq | |
# Set up environment variables | |
os.environ["GROQ_API_KEY"] = "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" | |
os.environ["SERPER_API_KEY"] = "206256c6acfbcd5a46195f3312aaa7e8ed38ae5f" | |
# Initialize Groq LLM | |
groq_llm = ChatGroq( | |
model_name="mixtral-8x7b-32768", | |
temperature=0.7, | |
max_tokens=32768 | |
) | |
# Initialize search tool | |
search_tool = SerperDevTool() | |
# Define agents | |
researcher = 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 interface | |
iface = 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 interface | |
iface.launch() |