Spaces:
Build error
Build error
import streamlit as st | |
import torch | |
from transformers import GPT2Tokenizer, GPT2Model | |
tokenizer = GPT2Tokenizer.from_pretrained('gpt2') | |
model = GPT2Model.from_pretrained('gpt2') | |
st.title("GPT-2 Text Generation") | |
text = st.text_input("Enter the starting text:", "Replace me by any text you'd like.") | |
if st.button("Generate"): | |
encoded_input = tokenizer(text, return_tensors='pt', padding=False, truncation=False) | |
output = model(**encoded_input) | |
generated_text = tokenizer.decode(torch.argmax(output[0], dim=1), skip_special_tokens=True) | |
st.write(generated_text) | |