Nick088 commited on
Commit
a1befb3
1 Parent(s): c9744e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -18
app.py CHANGED
@@ -11,13 +11,11 @@ else:
11
  print("Using CPU")
12
 
13
  tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-small")
14
-
15
 
16
  def generate(prompt, model_precision_type, max_new_tokens, repetition_penalty, temperature, top_p, top_k, seed):
17
-
18
  model = T5ForConditionalGeneration.from_pretrained("roborovski/superprompt-v1", device_map="auto", torch_dtype=model_precision_type)
19
  model.to(device)
20
-
21
  input_text = f"Expand the following prompt to add more detail: {prompt}"
22
  input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
23
 
@@ -26,7 +24,7 @@ def generate(prompt, model_precision_type, max_new_tokens, repetition_penalty, t
26
  torch.manual_seed(seed)
27
  else:
28
  torch.manual_seed(seed)
29
-
30
  outputs = model.generate(
31
  input_ids,
32
  max_new_tokens=max_new_tokens,
@@ -38,18 +36,17 @@ def generate(prompt, model_precision_type, max_new_tokens, repetition_penalty, t
38
  )
39
 
40
  better_prompt = tokenizer.decode(outputs[0])
41
- better_prompt = better_prompt.replace("<pad>", "").replace("</s>", "")
42
  return better_prompt
43
 
44
-
45
  prompt = gr.Textbox(label="Prompt", interactive=True)
46
 
47
- model_precision_type = gr.Dropdown(choices=[('fp16', torch.float16), ('fp32', torch.float32)], type="value", value=torch.float16, label="Model Precision", info="fp16 is faster, fp32 is more precise"),
48
 
49
  max_new_tokens = gr.Slider(value=512, minimum=250, maximum=512, step=1, interactive=True, label="Max New Tokens", info="The maximum numbers of new tokens, controls how long is the output")
50
-
51
  repetition_penalty = gr.Slider(value=1.2, minimum=0, maximum=2, step=0.05, interactive=True, label="Repetition Penalty", info="Penalize repeated tokens, making the AI repeat less itself")
52
-
53
  temperature = gr.Slider(value=0.5, minimum=0, maximum=1, step=0.05, interactive=True, label="Temperature", info="Higher values produce more diverse outputs")
54
 
55
  top_p = gr.Slider(value=1, minimum=0, maximum=2, step=0.05, interactive=True, label="Top P", info="Higher values sample more low-probability tokens")
@@ -59,15 +56,7 @@ top_k = gr.Slider(value=1, minimum=1, maximum=100, step=1, interactive=True, lab
59
  seed = gr.Number(value=42, interactive=True, label="Seed", info="A starting point to initiate the generation process, put 0 for a random one")
60
 
61
  examples = [
62
- [
63
- "A storefront with 'Text to Image' written on it.",
64
- 512,
65
- 1.2,
66
- 0.5,
67
- 1,
68
- 50,
69
- 42,
70
- ]
71
  ]
72
 
73
  gr.Interface(
 
11
  print("Using CPU")
12
 
13
  tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-small")
 
14
 
15
  def generate(prompt, model_precision_type, max_new_tokens, repetition_penalty, temperature, top_p, top_k, seed):
 
16
  model = T5ForConditionalGeneration.from_pretrained("roborovski/superprompt-v1", device_map="auto", torch_dtype=model_precision_type)
17
  model.to(device)
18
+
19
  input_text = f"Expand the following prompt to add more detail: {prompt}"
20
  input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
21
 
 
24
  torch.manual_seed(seed)
25
  else:
26
  torch.manual_seed(seed)
27
+
28
  outputs = model.generate(
29
  input_ids,
30
  max_new_tokens=max_new_tokens,
 
36
  )
37
 
38
  better_prompt = tokenizer.decode(outputs[0])
39
+ better_prompt = better_prompt.replace("<pad>", "").replace("<|endoftext|>", "")
40
  return better_prompt
41
 
 
42
  prompt = gr.Textbox(label="Prompt", interactive=True)
43
 
44
+ model_precision_type = gr.Dropdown(choices=[('fp16', torch.float16), ('fp32', torch.float32)], type="value", value=torch.float16, label="Model Precision", info="fp16 is faster, fp32 is more precise")
45
 
46
  max_new_tokens = gr.Slider(value=512, minimum=250, maximum=512, step=1, interactive=True, label="Max New Tokens", info="The maximum numbers of new tokens, controls how long is the output")
47
+
48
  repetition_penalty = gr.Slider(value=1.2, minimum=0, maximum=2, step=0.05, interactive=True, label="Repetition Penalty", info="Penalize repeated tokens, making the AI repeat less itself")
49
+
50
  temperature = gr.Slider(value=0.5, minimum=0, maximum=1, step=0.05, interactive=True, label="Temperature", info="Higher values produce more diverse outputs")
51
 
52
  top_p = gr.Slider(value=1, minimum=0, maximum=2, step=0.05, interactive=True, label="Top P", info="Higher values sample more low-probability tokens")
 
56
  seed = gr.Number(value=42, interactive=True, label="Seed", info="A starting point to initiate the generation process, put 0 for a random one")
57
 
58
  examples = [
59
+ ["A storefront with 'Text to Image' written on it.", "fp16", 512, 1.2, 0.5, 1, 50, 42]
 
 
 
 
 
 
 
 
60
  ]
61
 
62
  gr.Interface(