File size: 961 Bytes
437556b
c38ee55
17c5657
 
 
 
80d20fa
 
 
437556b
 
17c5657
 
28d6912
 
7b543b7
 
17c5657
 
437556b
 
 
c38ee55
437556b
 
17c5657
 
80d20fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)