File size: 919 Bytes
575198c
12c43aa
575198c
12c43aa
 
 
 
575198c
12c43aa
 
 
575198c
 
12c43aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import GPT2LMHeadModel, GPT2Tokenizer

# Load the GPT-2 model and tokenizer
model_name = "gpt2"
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
model = GPT2LMHeadModel.from_pretrained(model_name)

# Streamlit app layout
st.title("Blog Post Generator")
topic = st.text_input("Enter a topic for your blog post:")

if st.button("Generate Blog Post"):
    if topic:
        # Encode the input topic
        input_ids = tokenizer.encode(topic, return_tensors='pt')
        
        # Generate text
        output = model.generate(input_ids, max_length=500, num_return_sequences=1)
        
        # Decode the generated text
        blog_post = tokenizer.decode(output[0], skip_special_tokens=True)
        
        # Display the generated blog post
        st.subheader("Generated Blog Post:")
        st.write(blog_post)
    else:
        st.warning("Please enter a topic.")