abdiharyadi commited on
Commit
7894523
1 Parent(s): e18c38e

feat: add update states

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -6,13 +6,20 @@ gpt_tokenizer = IndoNLGTokenizer.from_pretrained("indobenchmark/indogpt")
6
  gpt_tokenizer.pad_token = gpt_tokenizer.eos_token
7
  kancilgpt = GPT2LMHeadModel.from_pretrained("abdiharyadi/kancilgpt")
8
 
9
- def generate_story(judul: str):
10
- yield "...", "..."
11
-
12
  stop = False
 
13
  while not stop:
 
 
 
14
  gpt_input = gpt_tokenizer('<s> awal cerita | judul:', return_tensors='pt')
15
- gpt_out = kancilgpt.generate(**gpt_input, do_sample=True, max_length=512, pad_token_id=gpt_tokenizer.eos_token_id)
 
 
 
 
 
16
  result = gpt_tokenizer.decode(gpt_out[0])
17
  _, judul_prompt, isi, *end_part = result.split(" | ")
18
  end_part = "".join(end_part)
@@ -36,12 +43,12 @@ def generate_story(judul: str):
36
 
37
  stop = True
38
 
39
- yield judul, isi + " ..."
40
-
41
  total_isi = isi
42
 
 
43
  while not end_part.startswith("tamat"):
44
- yield judul, total_isi + " ..."
 
45
 
46
  i = 0
47
  in_quote = False
@@ -98,14 +105,14 @@ def generate_story(judul: str):
98
  stop = True
99
 
100
  total_isi += " " + isi[len(next_isi) + 1:]
 
101
 
102
- yield judul, total_isi + "\n\ntamat."
103
 
104
  demo = gr.Interface(
105
  fn=generate_story,
106
  inputs=None,
107
  outputs=[
108
- gr.Textbox(label="judul", lines=1),
109
  gr.Textbox(label="cerita", lines=7)
110
  ]
111
  )
 
6
  gpt_tokenizer.pad_token = gpt_tokenizer.eos_token
7
  kancilgpt = GPT2LMHeadModel.from_pretrained("abdiharyadi/kancilgpt")
8
 
9
+ def generate_story():
 
 
10
  stop = False
11
+ ellipsis = "..."
12
  while not stop:
13
+ yield f"(memuat cerita {ellipsis})"
14
+ ellipsis += "."
15
+
16
  gpt_input = gpt_tokenizer('<s> awal cerita | judul:', return_tensors='pt')
17
+ gpt_out = kancilgpt.generate(
18
+ **gpt_input,
19
+ do_sample=True,
20
+ max_length=512,
21
+ pad_token_id=gpt_tokenizer.eos_token_id
22
+ )
23
  result = gpt_tokenizer.decode(gpt_out[0])
24
  _, judul_prompt, isi, *end_part = result.split(" | ")
25
  end_part = "".join(end_part)
 
43
 
44
  stop = True
45
 
 
 
46
  total_isi = isi
47
 
48
+ ellipsis = "..."
49
  while not end_part.startswith("tamat"):
50
+ yield judul + "\n" + ("-" * len(judul)) + "\n" + total_isi + f" {ellipsis}"
51
+ ellipsis += "."
52
 
53
  i = 0
54
  in_quote = False
 
105
  stop = True
106
 
107
  total_isi += " " + isi[len(next_isi) + 1:]
108
+ ellipsis = "..."
109
 
110
+ yield judul + "\n" + ("-" * len(judul)) + "\n" + total_isi + "\n\ntamat."
111
 
112
  demo = gr.Interface(
113
  fn=generate_story,
114
  inputs=None,
115
  outputs=[
 
116
  gr.Textbox(label="cerita", lines=7)
117
  ]
118
  )