Text-Generation / app.py
AhsanShahid's picture
Update app.py
338b4ff verified
raw
history blame
850 Bytes
import streamlit as st
from transformers import pipeline
# Load GPT-2 model and tokenizer
@st.cache(allow_output_mutation=True)
def load_model():
return pipeline("text-generation", model="gpt-2")
model = load_model()
st.title("Blog Post Generator")
st.write("Generate a blog post for a given topic using GPT-2.")
# User input for the blog post topic
topic = st.text_input("Enter the topic for your blog post:")
# Generate blog post button
if st.button("Generate Blog Post"):
if topic:
# Generate the blog post using GPT-2
result = model(f"Write a blog post about {topic}.", max_length=500, num_return_sequences=1)
blog_post = result[0]['generated_text']
st.write("### Generated Blog Post:")
st.write(blog_post)
else:
st.write("Please enter a topic to generate a blog post.")