Nick088 commited on
Commit
1aa631a
1 Parent(s): 714b39e

Switched from chatinterface to normal interface and has better use random seed option

Browse files
Files changed (1) hide show
  1. app.py +25 -66
app.py CHANGED
@@ -16,8 +16,8 @@ else:
16
  model.to(device)
17
 
18
  def generate(
 
19
  prompt,
20
- history,
21
  max_new_tokens,
22
  repetition_penalty,
23
  temperature,
@@ -27,7 +27,7 @@ def generate(
27
  seed,
28
  ):
29
 
30
- input_text = f"{prompt}, {history}"
31
  input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
32
 
33
  if random_seed:
@@ -49,69 +49,29 @@ def generate(
49
  better_prompt = tokenizer.decode(outputs[0])
50
  return better_prompt
51
 
52
- use_random_seed = gr.Checkbox(value=False, label="Use Random Seed", info="Check to use a random seed which is a start point for the generation process")
53
-
54
-
55
- additional_inputs = [
56
- gr.Slider(
57
- value=512,
58
- minimum=250,
59
- maximum=512,
60
- step=1,
61
- interactive=True,
62
- label="Max New Tokens",
63
- info="The maximum numbers of new tokens, controls how long is the output",
64
- ),
65
- gr.Slider(
66
- value=1.2,
67
- minimum=0,
68
- maximum=2,
69
- step=0.05,
70
- interactive=True,
71
- label="Repetition Penalty",
72
- info="Penalize repeated tokens, making the AI repeat less itself",
73
- ),
74
- gr.Slider(
75
- value=0.5,
76
- minimum=0,
77
- maximum=1,
78
- step=0.05,
79
- interactive=True,
80
- label="Temperature",
81
- info="Higher values produce more diverse outputs",
82
- ),
83
- gr.Slider(
84
- value=1,
85
- minimum=0,
86
- maximum=2,
87
- step=0.05,
88
- interactive=True,
89
- label="Top P",
90
- info="Higher values sample more low-probability tokens",
91
- ),
92
- gr.Slider(
93
- value=1,
94
- minimum=1,
95
- maximum=100,
96
- step=1,
97
- interactive=True,
98
- label="Top K",
99
- info="Higher k means more diverse outputs by considering a range of tokens",
100
- ),
101
- use_random_seed,
102
- gr.Number(
103
- value=42,
104
- interactive=True,
105
- label="Manual Seed",
106
- info="A starting point to initiate the generation process",
107
- visible={'False' if use_random_seed else 'True'}
108
- ),
109
- ]
110
 
111
 
112
  examples = [
113
  [
114
- "Expand the following prompt to add more detail: A storefront with 'Text to Image' written on it.",
 
115
  512,
116
  1.2,
117
  0.5,
@@ -122,14 +82,13 @@ examples = [
122
  ]
123
  ]
124
 
125
- gr.ChatInterface(
126
  fn=generate,
127
- chatbot=gr.Chatbot(
128
- show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"
129
- ),
130
- additional_inputs=additional_inputs,
131
  title="SuperPrompt-v1",
132
  description="Make your prompts more detailed!",
133
  examples=examples,
 
134
  concurrency_limit=20,
135
  ).launch(show_api=False)
 
16
  model.to(device)
17
 
18
  def generate(
19
+ system_prompt,
20
  prompt,
 
21
  max_new_tokens,
22
  repetition_penalty,
23
  temperature,
 
27
  seed,
28
  ):
29
 
30
+ input_text = f"{system_prompt}, {prompt}"
31
  input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
32
 
33
  if random_seed:
 
49
  better_prompt = tokenizer.decode(outputs[0])
50
  return better_prompt
51
 
52
+ prompt = gr.Textbox(label="Prompt", interactive=True)
53
+
54
+ system_prompt = gr.Textbox(label="System Prompt", interactive=True)
55
+
56
+ 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")
57
+
58
+ 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")
59
+
60
+ temperature = gr.Slider(value=0.5, minimum=0, maximum=1, step=0.05, interactive=True, label="Temperature", info="Higher values produce more diverse outputs")
61
+
62
+ 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")
63
+
64
+ top_k = gr.Slider(value=1, minimum=1, maximum=100, step=1, interactive=True, label="Top K", info="Higher k means more diverse outputs by considering a range of tokens")
65
+
66
+ use_random_seed = gr.Checkbox(value=False, label="Use Random Seed", info="Check to use a random seed which is a start point for the generation process")
67
+
68
+ manual_seed = gr.Number(value=42, interactive=True, label="Manual Seed", info="A starting point to initiate the generation process", visible={'False' if use_random_seed else 'True'})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
 
71
  examples = [
72
  [
73
+ "A storefront with 'Text to Image' written on it.",
74
+ "Expand the following prompt to add more detail:",
75
  512,
76
  1.2,
77
  0.5,
 
82
  ]
83
  ]
84
 
85
+ gr.Interface(
86
  fn=generate,
87
+ inputs=[prompt, system_prompt, max_new_tokens, repetition_penalty, temperature, top_p, top_k, use_random_seed, manual_seed]
88
+ outputs=gr.Textbox(label="Better Prompt", interactive=True)
 
 
89
  title="SuperPrompt-v1",
90
  description="Make your prompts more detailed!",
91
  examples=examples,
92
+ live=True
93
  concurrency_limit=20,
94
  ).launch(show_api=False)