File size: 768 Bytes
48d79f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from char_tokenizer import CharTokenizer
import gradio as gr
from transformers import GPT2LMHeadModel

tokenizer = CharTokenizer.load("saved_model/tokenizer.json")
model = GPT2LMHeadModel.from_pretrained("saved_model")
def generation(prompt, length):
    tokens = tokenizer(prompt=str(length) + prompt)
    output_ids = model.generate(tokens['input_ids'],
                                   do_sample=True, 
                                   top_p=0.95,
                                   max_length=100)
    decoded_verse = tokenizer.decode(output_ids)[len(prompt) + 1:]
    return decoded_verse

input_prompt = gr.inputs.Textbox()
input_length = gr.inputs.Dropdown([5, 6, 7])
gr.Interface(fn=generation, inputs=[input_prompt, input_length], outputs="text").launch()