Nick088 commited on
Commit
f97bf68
1 Parent(s): 3331811

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +49 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
4
+
5
+ if torch.cuda.is_available():
6
+ device = "cuda"
7
+ print("Using GPU")
8
+ else:
9
+ device = "cpu"
10
+ print("Using CPU")
11
+
12
+ tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-small")
13
+ model = T5ForConditionalGeneration.from_pretrained("roborovski/superprompt-v1", torch_dtype=torch.float16)
14
+
15
+
16
+ def generate(
17
+ prompt, history, temperature=0.9, max_new_tokens=250, repetition_penalty=1.0,
18
+ ):
19
+
20
+ input_text = f"{prompt}, {history}"
21
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
22
+ outputs = model.generate(input_ids, max_new_tokens=max_new_tokens, repetition_penalty=repetition_penalty)
23
+ better_prompt = tokenizer.decode(outputs[0])
24
+ return better_prompt
25
+
26
+
27
+ additional_inputs=[
28
+ gr.Slider(
29
+ label="Repetition penalty",
30
+ value=1.2,
31
+ minimum=1.0,
32
+ maximum=2.0,
33
+ step=0.05,
34
+ interactive=True,
35
+ info="Penalize repeated tokens",
36
+ )
37
+ ]
38
+
39
+ examples=[["Expand the following prompt to add more detail: A storefront with 'Text to Image' written on it.", None, None ]]
40
+
41
+ gr.ChatInterface(
42
+ fn=generate,
43
+ chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
44
+ additional_inputs=additional_inputs,
45
+ title="SuperPrompt-v1",
46
+ description="Make your prompts more detailed! Especially for AI Art!!!",
47
+ examples=examples,
48
+ concurrency_limit=20,
49
+ ).launch(show_api=False)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ sentencepiece
3
+ torch