3words / app.py
junefisher's picture
Update app.py
5aa7dec
raw
history blame
580 Bytes
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)