Update app.py
Browse files
app.py
CHANGED
@@ -12,9 +12,10 @@ else:
|
|
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)
|
@@ -41,8 +42,6 @@ def generate(prompt, model_precision_type, max_new_tokens, repetition_penalty, t
|
|
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='fp16', 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")
|
@@ -56,12 +55,12 @@ top_k = gr.Slider(value=1, minimum=1, maximum=100, step=1, interactive=True, lab
|
|
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.",
|
60 |
]
|
61 |
|
62 |
gr.Interface(
|
63 |
fn=generate,
|
64 |
-
inputs=[prompt,
|
65 |
outputs=gr.Textbox(label="Better Prompt"),
|
66 |
title="SuperPrompt-v1",
|
67 |
description='Make your prompts more detailed! <br> <a href="https://huggingface.co/roborovski/superprompt-v1">Model used</a> <br> <a href="https://brianfitzgerald.xyz/prompt-augmentation/">Model Blog</a> <br> Task Prefix: "Expand the following prompt to add more detail:" is already setted! <br> Hugging Face Space made by [Nick088](https://linktr.ee/Nick088)',
|
|
|
12 |
|
13 |
tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-small")
|
14 |
|
15 |
+
model = T5ForConditionalGeneration.from_pretrained("roborovski/superprompt-v1", device_map="auto", torch_dtype=auto)
|
16 |
+
model.to(device)
|
17 |
+
|
18 |
def generate(prompt, model_precision_type, max_new_tokens, repetition_penalty, temperature, top_p, top_k, seed):
|
|
|
|
|
19 |
|
20 |
input_text = f"Expand the following prompt to add more detail: {prompt}"
|
21 |
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
|
|
|
42 |
|
43 |
prompt = gr.Textbox(label="Prompt", interactive=True)
|
44 |
|
|
|
|
|
45 |
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")
|
46 |
|
47 |
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")
|
|
|
55 |
seed = gr.Number(value=42, interactive=True, label="Seed", info="A starting point to initiate the generation process, put 0 for a random one")
|
56 |
|
57 |
examples = [
|
58 |
+
["A storefront with 'Text to Image' written on it.", 512, 1.2, 0.5, 1, 50, 42]
|
59 |
]
|
60 |
|
61 |
gr.Interface(
|
62 |
fn=generate,
|
63 |
+
inputs=[prompt, max_new_tokens, repetition_penalty, temperature, top_p, top_k, seed],
|
64 |
outputs=gr.Textbox(label="Better Prompt"),
|
65 |
title="SuperPrompt-v1",
|
66 |
description='Make your prompts more detailed! <br> <a href="https://huggingface.co/roborovski/superprompt-v1">Model used</a> <br> <a href="https://brianfitzgerald.xyz/prompt-augmentation/">Model Blog</a> <br> Task Prefix: "Expand the following prompt to add more detail:" is already setted! <br> Hugging Face Space made by [Nick088](https://linktr.ee/Nick088)',
|