Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,44 @@
|
|
| 1 |
-
from crewai import Crew
|
| 2 |
-
from tasks import plan_task, write_task, edit_task
|
| 3 |
-
import gradio as gr
|
| 4 |
-
|
| 5 |
-
# Initialize Crew with agents and their tasks
|
| 6 |
-
blog_crew = Crew(
|
| 7 |
-
agents=[plan_task.agent, write_task.agent, edit_task.agent],
|
| 8 |
-
tasks=[plan_task, write_task, edit_task],
|
| 9 |
-
verbose=True
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
# Function to run the blog creation workflow
|
| 13 |
-
def generate_blog(topic):
|
| 14 |
-
if not topic or topic.strip() == "":
|
| 15 |
-
return "❌ Error: Please enter a valid topic for the blog post."
|
| 16 |
-
if len(topic.strip()) < 5:
|
| 17 |
-
return "❌ Error: The topic is too short. Please provide a more detailed topic."
|
| 18 |
-
|
| 19 |
-
print(f"Starting the Blog Writer Multi-Agent System for topic: {topic}")
|
| 20 |
-
try:
|
| 21 |
-
inputs = {"topic": topic}
|
| 22 |
-
result = blog_crew.kickoff(inputs=inputs)
|
| 23 |
-
print("Blog content creation completed!")
|
| 24 |
-
return result
|
| 25 |
-
except Exception as e:
|
| 26 |
-
print(f"An error occurred: {e}")
|
| 27 |
-
return f"❌ Error: Failed to generate the blog post. Please try again with a different topic."
|
| 28 |
-
|
| 29 |
-
# Gradio Interface
|
| 30 |
-
def gradio_interface(topic):
|
| 31 |
-
blog_content = generate_blog(topic)
|
| 32 |
-
return blog_content
|
| 33 |
-
|
| 34 |
-
# Create Gradio app
|
| 35 |
-
interface = gr.Interface(
|
| 36 |
-
fn=gradio_interface,
|
| 37 |
-
inputs=gr.Textbox(lines=2, placeholder="Enter the topic for your blog post...", label="Blog Topic"),
|
| 38 |
-
outputs=gr.Textbox(lines=20, label="Generated Blog Post"),
|
| 39 |
-
title="AI-Powered Blog Writer",
|
| 40 |
-
description="A Multi-Agent System for Automated Content Creation. Enter a topic, and the system will generate a blog post for you!"
|
| 41 |
-
)
|
| 42 |
-
|
| 43 |
-
# Run the Gradio app
|
| 44 |
-
|
| 45 |
-
interface.launch()
|
|
|
|
| 1 |
+
from crewai import Crew
|
| 2 |
+
from tasks import plan_task, write_task, edit_task
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Initialize Crew with agents and their tasks
|
| 6 |
+
blog_crew = Crew(
|
| 7 |
+
agents=[plan_task.agent, write_task.agent, edit_task.agent],
|
| 8 |
+
tasks=[plan_task, write_task, edit_task],
|
| 9 |
+
verbose=True
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
# Function to run the blog creation workflow
|
| 13 |
+
def generate_blog(topic):
|
| 14 |
+
if not topic or topic.strip() == "":
|
| 15 |
+
return "❌ Error: Please enter a valid topic for the blog post."
|
| 16 |
+
if len(topic.strip()) < 5:
|
| 17 |
+
return "❌ Error: The topic is too short. Please provide a more detailed topic."
|
| 18 |
+
|
| 19 |
+
print(f"Starting the Blog Writer Multi-Agent System for topic: {topic}")
|
| 20 |
+
try:
|
| 21 |
+
inputs = {"topic": topic}
|
| 22 |
+
result = blog_crew.kickoff(inputs=inputs)
|
| 23 |
+
print("Blog content creation completed!")
|
| 24 |
+
return result
|
| 25 |
+
except Exception as e:
|
| 26 |
+
print(f"An error occurred: {e}")
|
| 27 |
+
return f"❌ Error: Failed to generate the blog post. Please try again with a different topic."
|
| 28 |
+
|
| 29 |
+
# Gradio Interface
|
| 30 |
+
def gradio_interface(topic):
|
| 31 |
+
blog_content = generate_blog(topic)
|
| 32 |
+
return blog_content
|
| 33 |
+
|
| 34 |
+
# Create Gradio app
|
| 35 |
+
interface = gr.Interface(
|
| 36 |
+
fn=gradio_interface,
|
| 37 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter the topic for your blog post...", label="Blog Topic"),
|
| 38 |
+
outputs=gr.Textbox(lines=20, label="Generated Blog Post"),
|
| 39 |
+
title="AI-Powered Blog Writer",
|
| 40 |
+
description="A Multi-Agent System for Automated Content Creation. Enter a topic, and the system will generate a blog post for you!"
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
# Run the Gradio app
|
| 44 |
+
interface.launch()
|
|
|