Nguyen17 commited on
Commit
88daf83
·
verified ·
1 Parent(s): 250e8fd
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -9,22 +9,26 @@ model = GPT2LMHeadModel.from_pretrained('NlpHUST/gpt2-vietnamese')
9
 
10
 
11
  def run(text, intensity):
12
- res=""
13
- max_length=intensity
 
 
 
 
14
  input_ids = tokenizer.encode(text, return_tensors='pt')
15
  sample_outputs = model.generate(input_ids,pad_token_id=tokenizer.eos_token_id,
16
  do_sample=True,
17
  max_length=max_length,
18
- min_length=max_length,
19
  top_k=40,
20
  num_beams=5,
21
  early_stopping=True,
22
  no_repeat_ngram_size=2,
23
- num_return_sequences=3)
24
 
25
  for i, sample_output in enumerate(sample_outputs):
26
- res +="Generated text {}\n\n{}".format(i+1, tokenizer.decode(sample_output.tolist()))
27
- res +='\n---'
28
  return res
29
 
30
  demo = gr.Interface(
 
9
 
10
 
11
  def run(text, intensity):
12
+ res="NlpHUST model \n"
13
+ if (intensity>=10):
14
+ max_length=intensity
15
+ else:
16
+ max_length=10
17
+
18
  input_ids = tokenizer.encode(text, return_tensors='pt')
19
  sample_outputs = model.generate(input_ids,pad_token_id=tokenizer.eos_token_id,
20
  do_sample=True,
21
  max_length=max_length,
22
+ min_length=5,
23
  top_k=40,
24
  num_beams=5,
25
  early_stopping=True,
26
  no_repeat_ngram_size=2,
27
+ num_return_sequences=2)
28
 
29
  for i, sample_output in enumerate(sample_outputs):
30
+ res +="Mẫu số {}\n\n{}".format(i+1, tokenizer.decode(sample_output.tolist()))
31
+ res +='\n'
32
  return res
33
 
34
  demo = gr.Interface(