SyedHasanCronosPMC commited on
Commit
befd505
·
verified ·
1 Parent(s): c310de8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from crewai import Agent, Task, Crew
3
+
4
+ # Define Agents
5
+ researcher = Agent(
6
+ role="Senior Research Specialist",
7
+ goal="Uncover intricate insights into the given topic",
8
+ backstory="A seasoned expert in extracting valuable information and providing detailed analysis on any given subject.",
9
+ allow_delegation=False
10
+ )
11
+
12
+ writer = Agent(
13
+ role="Content Writer",
14
+ goal="Craft engaging and informative articles",
15
+ backstory="An experienced content writer who can turn complex research into easy-to-understand and engaging articles.",
16
+ allow_delegation=False
17
+ )
18
+
19
+ editor = Agent(
20
+ role="Content Editor",
21
+ goal="Ensure articles are polished, coherent, and engaging",
22
+ backstory="An expert editor with a sharp eye for clarity, grammar, and flow, capable of turning drafts into publication-ready articles.",
23
+ allow_delegation=False
24
+ )
25
+
26
+ # Function to setup tasks and run CrewAI
27
+ def run_crewai_article_writer(topic):
28
+ research_task = Task(
29
+ description=f"Conduct in-depth research on the topic: {topic} and provide a structured summary.",
30
+ expected_output="A structured and detailed research summary covering important aspects, recent developments, and insights related to the topic.",
31
+ agent=researcher
32
+ )
33
+
34
+ writing_task = Task(
35
+ description=f"Using the research, write a full-length article on the topic: {topic} in 1000 words with various subsections.",
36
+ expected_output="An engaging, detailed, informative, and coherent article suitable for online publication.",
37
+ agent=writer
38
+ )
39
+
40
+ editing_task = Task(
41
+ description=f"Review and edit the article on {topic} for clarity, grammar, flow, and engagement.",
42
+ expected_output="A polished, clear, and professionally edited final version of the article.",
43
+ agent=editor
44
+ )
45
+
46
+ crew = Crew(
47
+ agents=[researcher, writer, editor],
48
+ tasks=[research_task, writing_task, editing_task],
49
+ verbose=True
50
+ )
51
+
52
+ return crew.kickoff()
53
+
54
+ # Gradio Interface
55
+ def generate_article(topic):
56
+ return run_crewai_article_writer(topic)
57
+
58
+ iface = gr.Interface(
59
+ fn=generate_article,
60
+ inputs=gr.Textbox(lines=2, placeholder="Enter a topic for the article..."),
61
+ outputs=gr.Textbox(lines=25, label="Generated Article"),
62
+ title="🧠 CrewAI Article Generator",
63
+ description="Powered by CrewAI: Research, Write, and Edit a high-quality article from a single topic prompt."
64
+ )
65
+
66
+ if __name__ == "__main__":
67
+ iface.launch()