File size: 1,594 Bytes
82f2fb9
32f2451
 
 
 
 
 
 
 
 
 
652c199
 
88daf83
32f2451
 
 
 
88daf83
32f2451
 
 
 
88daf83
32f2451
 
652c199
 
32f2451
 
652c199
 
 
 
 
32f2451
652c199
 
 
 
32f2451
652c199
32f2451
 
 
 
 
 
82f2fb9
 
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
42
43
44
45
46
47
48
49
50
51
import gradio as gr
import torch
from transformers import GPT2Tokenizer, GPT2LMHeadModel


tokenizer = GPT2Tokenizer.from_pretrained('NlpHUST/gpt2-vietnamese')
model = GPT2LMHeadModel.from_pretrained('NlpHUST/gpt2-vietnamese')
# max_length = 100


def run(text, intensity):
    res="Tham khảo NlpHUST model  \n  \n  \n"
    max_length=intensity
        
    input_ids = tokenizer.encode(text, return_tensors='pt')
    sample_outputs = model.generate(input_ids,pad_token_id=tokenizer.eos_token_id,
                                   do_sample=True,
                                   max_length=max_length,
                                   min_length=5,
                                   top_k=40,
                                   num_beams=5,
                                   early_stopping=True,
                                   no_repeat_ngram_size=2,
                                   num_return_sequences=2)
    
    for i, sample_output in enumerate(sample_outputs):
        res +="Mẫu số {}\n \n{}".format(i+1, tokenizer.decode(sample_output.tolist()))
        res +='\n \n \n \n'
    return res

# demo = gr.Interface(
#     fn=run,
#     inputs=["text", "slider"],
#     outputs=["text"],
# )

demo = gr.Interface(fn=run,
                    inputs=[gr.Textbox(label="Nhập vào nội dung input",value="Con đường xưa em đi"),gr.Slider(label="Độ dài output muốn tạo ra", value=20, minimum=10, maximum=100, step=2)],
                    outputs=gr.Textbox(label="Output"),  # <-- Number of output components: 1
                    )

demo.launch()