TestSpaceGPT / app.py
aisah1's picture
Update app.py
7469f5d verified
raw
history blame
668 Bytes
import gradio
from os import system
system("pip3 install torch")
system("pip3 install transformers")
from transformers import AutoTokenizer,OpenAIGPTLMHeadModel
tokenizer = AutoTokenizer.from_pretrained("openai-community/openai-gpt")
model = OpenAIGPTLMHeadModel.from_pretrained("openai-community/openai-gpt")
def work(inp_text):
out = tokenizer.encode(inp_text,return_tensors="pt")
out = model.generate(
out,
max_new_tokens=20,
do_sample=True,
temperature=0.3,
)
out = tokenizer.decode(out[0])
return str(out)
demo = gradio.Interface(
fn=work,
inputs=["text"],
outputs=["text"],
)
demo.launch()