import streamlit as st from transformers import pipeline from crewai import Crew, Task # Initialize the summarization pipeline summarizer = pipeline("summarization") # Define functions for tasks def summarize_topic(topic): summary = summarizer(f"Summarize the topic: {topic}", max_length=100, min_length=30, do_sample=False) return summary[0]['summary_text'] def create_blog_post(summary): blog_post = f""" ### Blog Post: The Impact of AI in Modern Education {summary} In conclusion, AI is transforming education, making it more personalized and accessible. """ return blog_post # Function to run the Crew and get the blog post def get_blog_post(topic): # Define Task functions def research_task_func(): return {"summary": summarize_topic(topic)} def blog_task_func(summary): return {"blog_post": create_blog_post(summary)} # Create Task objects research_task = Task( name="Research Task", description="Summarizes the given topic", func=research_task_func ) # Initialize Crew blog_creation_crew = Crew( tasks=[research_task], verbose=True ) # Execute Crew results = blog_creation_crew.kickoff() # Retrieve summary summary = results["summary"] # Generate blog post blog_post = blog_task_func(summary) return blog_post["blog_post"] # Streamlit UI st.title("AI Blog Post Generator") topic = st.text_input("Enter a topic for the blog post:", "AI in Education") if st.button("Generate Blog Post"): if topic: blog_post = get_blog_post(topic) st.subheader("Generated Blog Post") st.write(blog_post) else: st.error("Please enter a topic.")