Nguyen17 commited on
Commit
1e864e9
1 Parent(s): 433aa17
Files changed (1) hide show
  1. app.py +38 -3
app.py CHANGED
@@ -1,7 +1,42 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  demo.launch()
 
1
  import gradio as gr
2
+ import torch
3
+ from transformers import GPT2Tokenizer, GPT2LMHeadModel
4
 
 
 
5
 
6
+ tokenizer = GPT2Tokenizer.from_pretrained('NlpHUST/gpt2-vietnamese')
7
+ model = GPT2LMHeadModel.from_pretrained('NlpHUST/gpt2-vietnamese')
8
+ # max_length = 100
9
+
10
+
11
+ def run(text, intensity):
12
+ res="Tham khảo NlpHUST model \n \n \n"
13
+ max_length=intensity
14
+
15
+ input_ids = tokenizer.encode(text, return_tensors='pt')
16
+ sample_outputs = model.generate(input_ids,pad_token_id=tokenizer.eos_token_id,
17
+ do_sample=True,
18
+ max_length=max_length,
19
+ min_length=5,
20
+ top_k=40,
21
+ num_beams=5,
22
+ early_stopping=True,
23
+ no_repeat_ngram_size=2,
24
+ num_return_sequences=2)
25
+
26
+ for i, sample_output in enumerate(sample_outputs):
27
+ res +="Mẫu số {}\n \n{}".format(i+1, tokenizer.decode(sample_output.tolist()))
28
+ res +='\n \n \n \n'
29
+ return res
30
+
31
+ # demo = gr.Interface(
32
+ # fn=run,
33
+ # inputs=["text", "slider"],
34
+ # outputs=["text"],
35
+ # )
36
+
37
+ demo = gr.Interface(fn=run,
38
+ 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)],
39
+ outputs=gr.Textbox(label="Output"), # <-- Number of output components: 1
40
+ )
41
+
42
  demo.launch()