|
import gradio as gr |
|
from crewai import Agent, Task, Crew |
|
|
|
|
|
researcher = Agent( |
|
role="Senior Research Specialist", |
|
goal="Uncover intricate insights into the given topic", |
|
backstory="A seasoned expert in extracting valuable information and providing detailed analysis on any given subject.", |
|
allow_delegation=False |
|
) |
|
|
|
writer = Agent( |
|
role="Content Writer", |
|
goal="Craft engaging and informative articles", |
|
backstory="An experienced content writer who can turn complex research into easy-to-understand and engaging articles.", |
|
allow_delegation=False |
|
) |
|
|
|
editor = Agent( |
|
role="Content Editor", |
|
goal="Ensure articles are polished, coherent, and engaging", |
|
backstory="An expert editor with a sharp eye for clarity, grammar, and flow, capable of turning drafts into publication-ready articles.", |
|
allow_delegation=False |
|
) |
|
|
|
|
|
def run_crewai_article_writer(topic): |
|
research_task = Task( |
|
description=f"Conduct in-depth research on the topic: {topic} and provide a structured summary.", |
|
expected_output="A structured and detailed research summary covering important aspects, recent developments, and insights related to the topic.", |
|
agent=researcher |
|
) |
|
|
|
writing_task = Task( |
|
description=f"Using the research, write a full-length article on the topic: {topic} in 1000 words with various subsections.", |
|
expected_output="An engaging, detailed, informative, and coherent article suitable for online publication.", |
|
agent=writer |
|
) |
|
|
|
editing_task = Task( |
|
description=f"Review and edit the article on {topic} for clarity, grammar, flow, and engagement.", |
|
expected_output="A polished, clear, and professionally edited final version of the article.", |
|
agent=editor |
|
) |
|
|
|
crew = Crew( |
|
agents=[researcher, writer, editor], |
|
tasks=[research_task, writing_task, editing_task], |
|
verbose=True |
|
) |
|
|
|
return crew.kickoff() |
|
|
|
|
|
def generate_article(topic): |
|
return run_crewai_article_writer(topic) |
|
|
|
iface = gr.Interface( |
|
fn=generate_article, |
|
inputs=gr.Textbox(lines=2, placeholder="Enter a topic for the article..."), |
|
outputs=gr.Textbox(lines=25, label="Generated Article"), |
|
title="🧠 CrewAI Article Generator", |
|
description="Powered by CrewAI: Research, Write, and Edit a high-quality article from a single topic prompt." |
|
) |
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|