p1atdev commited on
Commit
99a985f
·
1 Parent(s): e5e0fe8

chore: add examples

Browse files
Files changed (1) hide show
  1. app.py +33 -4
app.py CHANGED
@@ -7,7 +7,7 @@ from transformers import (
7
  AutoModelForPreTraining,
8
  AutoProcessor,
9
  AutoConfig,
10
- PreTrainedTokenizerFast
11
  )
12
  from huggingface_hub import hf_hub_download
13
  from safetensors.torch import load_file
@@ -21,15 +21,20 @@ DEVICE = torch.device("cuda")
21
 
22
  BAD_WORD_KEYWORDS = ["(medium)"]
23
 
 
24
  def fix_compiled_state_dict(state_dict: dict):
25
  return {k.replace("._orig_mod.", "."): v for k, v in state_dict.items()}
26
 
 
27
  def get_bad_words_ids(tokenizer: PreTrainedTokenizerFast):
28
  ids = [
29
- [id] for token, id in tokenizer.vocab.items() if any(word in token for word in BAD_WORD_KEYWORDS)
 
 
30
  ]
31
  return ids
32
 
 
33
  def prepare_models():
34
  config = AutoConfig.from_pretrained(MODEL_NAME, trust_remote_code=True)
35
  model = AutoModelForPreTraining.from_config(
@@ -89,6 +94,7 @@ def demo():
89
  temperature=temperature,
90
  top_k=top_k,
91
  top_p=top_p,
 
92
  eos_token_id=processor.decoder_tokenizer.eos_token_id,
93
  pad_token_id=processor.decoder_tokenizer.pad_token_id,
94
  bad_words_ids=ban_ids,
@@ -153,8 +159,31 @@ def demo():
153
  time_elapsed = gr.Markdown(value="")
154
 
155
  gr.Examples(
156
- examples=[["Miku is looking at viewer.", True]],
157
- inputs=[text, auto_detect],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  )
159
 
160
  gr.on(
 
7
  AutoModelForPreTraining,
8
  AutoProcessor,
9
  AutoConfig,
10
+ PreTrainedTokenizerFast,
11
  )
12
  from huggingface_hub import hf_hub_download
13
  from safetensors.torch import load_file
 
21
 
22
  BAD_WORD_KEYWORDS = ["(medium)"]
23
 
24
+
25
  def fix_compiled_state_dict(state_dict: dict):
26
  return {k.replace("._orig_mod.", "."): v for k, v in state_dict.items()}
27
 
28
+
29
  def get_bad_words_ids(tokenizer: PreTrainedTokenizerFast):
30
  ids = [
31
+ [id]
32
+ for token, id in tokenizer.vocab.items()
33
+ if any(word in token for word in BAD_WORD_KEYWORDS)
34
  ]
35
  return ids
36
 
37
+
38
  def prepare_models():
39
  config = AutoConfig.from_pretrained(MODEL_NAME, trust_remote_code=True)
40
  model = AutoModelForPreTraining.from_config(
 
94
  temperature=temperature,
95
  top_k=top_k,
96
  top_p=top_p,
97
+ no_repeat_ngram_size=1,
98
  eos_token_id=processor.decoder_tokenizer.eos_token_id,
99
  pad_token_id=processor.decoder_tokenizer.pad_token_id,
100
  bad_words_ids=ban_ids,
 
159
  time_elapsed = gr.Markdown(value="")
160
 
161
  gr.Examples(
162
+ examples=[
163
+ ["Miku is looking at viewer.", True, ""],
164
+ [
165
+ "Fujita Kotone, Tsukimura Temari, Hanami Saki from Gakuen Idolmaster. They are in the hole, there are some tables and chairs. One's face is shaded, one is crying, and one is 😊.",
166
+ True,
167
+ "",
168
+ ],
169
+ [
170
+ "A single girl wearing red hood is sleeping in the forest. View angle from above. grass field. many colorful flowers. Bright atmosphere.",
171
+ False,
172
+ "",
173
+ ],
174
+ ["Arona and Plana are hugging each other.", True, "blue archive"],
175
+ [
176
+ "There are two girls. A vivacious blonde gyaru leans against a classroom desk, her flashy accessories jingling as she gestures animatedly. Across from her stands the prim and proper class representative, her long black hair neatly framing her face as she listens attentively, occasionally adjusting her glasses with a delicate touch.",
177
+ False,
178
+ "",
179
+ ],
180
+ [
181
+ "1girl, solo, white and blue medium hair with side braid, dark blue parka with hoodie, looking at somewhere else viewer, cowboy shot",
182
+ False,
183
+ ""
184
+ ]
185
+ ],
186
+ inputs=[text, auto_detect, copyright_tags],
187
  )
188
 
189
  gr.on(