|
import streamlit as st |
|
from transformers import GPT2LMHeadModel, GPT2Tokenizer |
|
|
|
|
|
model_name = "gpt2" |
|
tokenizer = GPT2Tokenizer.from_pretrained(model_name) |
|
model = GPT2LMHeadModel.from_pretrained(model_name) |
|
|
|
|
|
st.title("Blog Post Generator") |
|
topic = st.text_input("Enter a topic for your blog post:") |
|
|
|
if st.button("Generate Blog Post"): |
|
if topic: |
|
|
|
input_ids = tokenizer.encode(topic, return_tensors='pt') |
|
|
|
|
|
output = model.generate(input_ids, max_length=500, num_return_sequences=1) |
|
|
|
|
|
blog_post = tokenizer.decode(output[0], skip_special_tokens=True) |
|
|
|
|
|
st.subheader("Generated Blog Post:") |
|
st.write(blog_post) |
|
else: |
|
st.warning("Please enter a topic.") |