Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -19,29 +19,30 @@ def generate(your_prompt, max_new_tokens, repetition_penalty, temperature, model
|
|
19 |
if seed == 0:
|
20 |
seed = random.randint(1, 2**32-1)
|
21 |
transformers.set_seed(seed)
|
22 |
-
|
23 |
if model_precision_type == "fp16":
|
24 |
dtype = torch.float16
|
25 |
elif model_precision_type == "fp32":
|
26 |
dtype = torch.float32
|
27 |
|
28 |
model.to(dtype)
|
29 |
-
|
30 |
-
input_text = f"Expand the following prompt to add more detail: {your_prompt}"
|
31 |
-
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
|
32 |
-
|
33 |
-
outputs = model.generate(
|
34 |
-
input_ids,
|
35 |
-
max_new_tokens=max_new_tokens,
|
36 |
-
repetition_penalty=repetition_penalty,
|
37 |
-
do_sample=True,
|
38 |
-
temperature=temperature,
|
39 |
-
top_p=top_p,
|
40 |
-
top_k=top_k,
|
41 |
-
)
|
42 |
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
|
47 |
your_prompt = gr.Textbox(label="Your Prompt", interactive=True)
|
@@ -71,4 +72,4 @@ gr.Interface(
|
|
71 |
title="SuperPrompt-v1",
|
72 |
description='Make your prompts more detailed! <br> <a href="https://github.com/Nick088Official/SuperPrompt-v1">Github Repository & 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)',
|
73 |
examples=examples,
|
74 |
-
).launch(
|
|
|
19 |
if seed == 0:
|
20 |
seed = random.randint(1, 2**32-1)
|
21 |
transformers.set_seed(seed)
|
22 |
+
|
23 |
if model_precision_type == "fp16":
|
24 |
dtype = torch.float16
|
25 |
elif model_precision_type == "fp32":
|
26 |
dtype = torch.float32
|
27 |
|
28 |
model.to(dtype)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
+
with torch.inference_mode():
|
31 |
+
input_text = f"Expand the following prompt to add more detail: {your_prompt}"
|
32 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
|
33 |
+
|
34 |
+
outputs = model.generate(
|
35 |
+
input_ids,
|
36 |
+
max_new_tokens=max_new_tokens,
|
37 |
+
repetition_penalty=repetition_penalty,
|
38 |
+
do_sample=True,
|
39 |
+
temperature=temperature,
|
40 |
+
top_p=top_p,
|
41 |
+
top_k=top_k,
|
42 |
+
)
|
43 |
+
|
44 |
+
better_prompt = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
45 |
+
return better_prompt
|
46 |
|
47 |
|
48 |
your_prompt = gr.Textbox(label="Your Prompt", interactive=True)
|
|
|
72 |
title="SuperPrompt-v1",
|
73 |
description='Make your prompts more detailed! <br> <a href="https://github.com/Nick088Official/SuperPrompt-v1">Github Repository & 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)',
|
74 |
examples=examples,
|
75 |
+
).launch(share=True)
|