import streamlit as st from transformers import pipeline # Load the text generation pipeline with gpt2-large try: generator = pipeline('text-generation', model='gpt2-large') st.write("Model loaded successfully.") except Exception as e: st.write(f"Error loading model: {e}") def generate_blog_post(topic): try: # Generate a blog post based on the given topic command = f"Here is a blog post on the topic - \"{topic}\": " command = command.lower() response = generator(command, max_length=500, num_return_sequences=1) return response[0]['generated_text'][len(command):] except Exception as e: return f"Error generating blog post: {e}" # Streamlit app st.title("Blog Post Generator") topic = st.text_input("Enter the topic for the blog post:") if st.button("Generate"): with st.spinner('Generating blog post...'): blog_post = generate_blog_post(topic) st.write(blog_post)