ZEGTIC / app.py
typesdigital's picture
Create app.py
c16406d verified
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"
# Set up environment variables
os.environ["GROQ_API_KEY"] = "YOUR_GROQ_API_KEY"
os.environ["SERPER_API_KEY"] = "YOUR_SERPER_API_KEY"
# 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
)
# Create tasks
def create_tasks(topic):
task1 = Task(
description=f"""Conduct a comprehensive analysis of the latest advancements in {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=f"""Using the insights provided about {topic}, 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
)
return [task1, task2]
# Function to run the crew
def run_crew(topic):
tasks = create_tasks(topic)
crew = Crew(
agents=[researcher, writer],
tasks=tasks,
verbose=2,
process=Process.sequential
)
result = crew.kickoff()
return result
# Gradio interface
def gradio_interface(topic):
result = run_crew(topic)
return result
# Create Gradio interface
iface = gr.Interface(
fn=gradio_interface,
inputs=gr.Textbox(lines=2, placeholder="Enter a topic for AI research and blog writing..."),
outputs="text",
title="AI Research and Blog Writing Assistant",
description="Enter a topic related to AI or technology, and the AI will research it and write a blog post.",
)
# Launch the interface
iface.launch(share=True)