File size: 1,410 Bytes
0263fca
4f5142e
0263fca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c51ba33
 
 
 
0263fca
5f61159
c51ba33
 
 
0263fca
c51ba33
 
0263fca
 
 
c51ba33
0263fca
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
import streamlit as st
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
import torch
# Load the model and tokenizer
model_name = "gpt2-large"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Streamlit app
st.title("Blog Post Generator (GPT-2 Large)")

# Input area for the topic
topic = st.text_area("Enter the topic for your blog post:")

# Generate button
if st.button("Generate Blog Post"):
    if topic:
        # Prepare the prompt
        prompt = f"Write a blog post about {topic}:\n\n"
            
        # Generate text
        generation_config = GenerationConfig(max_new_tokens=50, do_sample=True, temperature=0.7)

        # Tokenize the input
        inputs_encoded = tokenizer.encode(prompt, return_tensors="pt")

        # Model output
        model_output = model.generate(inputs_encoded["input_ids"], generation_config=generation_config)[0]
        
        # Decode the output
        output = tokenizer.decode(model_output, skip_special_tokens=True)
        
        # Display the generated blog post
        st.subheader("Generated Blog Post:")
        st.write(output)
    else:
        st.warning("Please enter a topic.")

# Add some information about the app
st.sidebar.header("About")
st.sidebar.info("This app uses the GPT-2 Large model to generate blog posts based on your input topic.")