Update app.py
Browse files
app.py
CHANGED
|
@@ -69,7 +69,7 @@ def truncate_to_last_words(text, n):
|
|
| 69 |
)
|
| 70 |
return result
|
| 71 |
|
| 72 |
-
def generate_text(model_name, input_text, decoding_method, max_length, use_last_words, num_last_words):
|
| 73 |
global stop_generation
|
| 74 |
stop_generation = False
|
| 75 |
|
|
@@ -90,7 +90,8 @@ def generate_text(model_name, input_text, decoding_method, max_length, use_last_
|
|
| 90 |
generation_args = {
|
| 91 |
"max_new_tokens": max_length,
|
| 92 |
"pad_token_id": tokenizer.eos_token_id,
|
| 93 |
-
"do_sample": decoding_method == "stochastic"
|
|
|
|
| 94 |
}
|
| 95 |
|
| 96 |
if decoding_method == "stochastic":
|
|
@@ -139,6 +140,11 @@ with gr.Blocks(title=title) as demo:
|
|
| 139 |
label="Max Tokens"
|
| 140 |
)
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
use_last_words = gr.Checkbox(
|
| 143 |
label="Use Last N Words",
|
| 144 |
value=False
|
|
@@ -177,7 +183,7 @@ with gr.Blocks(title=title) as demo:
|
|
| 177 |
|
| 178 |
generate_btn.click(
|
| 179 |
fn=generate_text,
|
| 180 |
-
inputs=[model_dropdown, input_text, decoding_method, max_length, use_last_words, num_last_words],
|
| 181 |
outputs=output_text
|
| 182 |
)
|
| 183 |
|
|
@@ -185,5 +191,4 @@ with gr.Blocks(title=title) as demo:
|
|
| 185 |
|
| 186 |
# Launch
|
| 187 |
if __name__ == "__main__":
|
| 188 |
-
demo.launch()
|
| 189 |
-
|
|
|
|
| 69 |
)
|
| 70 |
return result
|
| 71 |
|
| 72 |
+
def generate_text(model_name, input_text, decoding_method, max_length, use_last_words, num_last_words, repetition_penalty):
|
| 73 |
global stop_generation
|
| 74 |
stop_generation = False
|
| 75 |
|
|
|
|
| 90 |
generation_args = {
|
| 91 |
"max_new_tokens": max_length,
|
| 92 |
"pad_token_id": tokenizer.eos_token_id,
|
| 93 |
+
"do_sample": decoding_method == "stochastic",
|
| 94 |
+
"repetition_penalty": repetition_penalty
|
| 95 |
}
|
| 96 |
|
| 97 |
if decoding_method == "stochastic":
|
|
|
|
| 140 |
label="Max Tokens"
|
| 141 |
)
|
| 142 |
|
| 143 |
+
repetition_penalty = gr.Slider(
|
| 144 |
+
minimum=1.0, maximum=2.0, value=1.2, step=0.1,
|
| 145 |
+
label="Repetition Penalty (1.0=no penalty, higher=less repetition)"
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
use_last_words = gr.Checkbox(
|
| 149 |
label="Use Last N Words",
|
| 150 |
value=False
|
|
|
|
| 183 |
|
| 184 |
generate_btn.click(
|
| 185 |
fn=generate_text,
|
| 186 |
+
inputs=[model_dropdown, input_text, decoding_method, max_length, use_last_words, num_last_words, repetition_penalty],
|
| 187 |
outputs=output_text
|
| 188 |
)
|
| 189 |
|
|
|
|
| 191 |
|
| 192 |
# Launch
|
| 193 |
if __name__ == "__main__":
|
| 194 |
+
demo.launch()
|
|
|