Kohaku-Blueleaf commited on
Commit
89f225d
1 Parent(s): d5cd173

add model list

Browse files
Files changed (1) hide show
  1. app.py +23 -11
app.py CHANGED
@@ -4,16 +4,14 @@ from time import time_ns
4
  import spaces
5
  import gradio as gr
6
  import torch
7
- from huggingface_hub import Repository
8
- from llama_cpp import Llama, LLAMA_SPLIT_MODE_NONE
9
  from transformers import LlamaForCausalLM, LlamaTokenizer
10
 
11
  from kgen.generate import tag_gen
12
  from kgen.metainfo import SPECIAL, TARGET
13
 
14
 
15
- MODEL_PATH = "KBlueLeaf/DanTagGen"
16
- DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
17
  print(f"Using device: {DEVICE}")
18
 
19
 
@@ -113,12 +111,17 @@ masterpiece, newest, absurdres, {rating}"""
113
 
114
 
115
  if __name__ == "__main__":
116
- tokenizer = LlamaTokenizer.from_pretrained(MODEL_PATH)
117
- text_model = LlamaForCausalLM.from_pretrained(MODEL_PATH)
118
- text_model = text_model.eval().half().to(DEVICE)
 
 
 
 
119
 
120
  @spaces.GPU
121
  def wrapper(
 
122
  rating: str,
123
  artist: str,
124
  characters: str,
@@ -132,6 +135,7 @@ if __name__ == "__main__":
132
  escape_bracket: bool,
133
  temperature: float = 1.35,
134
  ):
 
135
  yield from get_result(
136
  text_model,
137
  tokenizer,
@@ -151,7 +155,8 @@ if __name__ == "__main__":
151
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
152
  gr.Markdown("""# DanTagGen beta DEMO""")
153
  with gr.Accordion("Introduction and Instructions"):
154
- gr.Markdown("""
 
155
  #### What is this:
156
  DanTagGen(Danbooru Tag Generator) is a LLM model designed for generating Danboou Tags with provided informations.<br>
157
  It aims to provide user a more convinient way to make prompts for Text2Image model which is trained on Danbooru datasets.
@@ -173,7 +178,8 @@ It aims to provide user a more convinient way to make prompts for Text2Image mod
173
  #### Notice
174
  The formated result use same format as what Kohaku-XL Delta used. <br>
175
  The performance of using the output from this demo for other model is not guaranteed.
176
- """)
 
177
  with gr.Row():
178
  with gr.Column(scale=4):
179
  with gr.Row():
@@ -198,9 +204,9 @@ The performance of using the output from this demo for other model is not guaran
198
  label="Target length",
199
  )
200
  with gr.Column(scale=2):
201
- general = gr.TextArea(label="Input your general tags")
202
  black_list = gr.TextArea(
203
- label="tag Black list (seperated by comma)"
204
  )
205
  with gr.Row():
206
  width = gr.Slider(
@@ -229,6 +235,11 @@ The performance of using the output from this demo for other model is not guaran
229
  value=False,
230
  label="Escape bracket",
231
  )
 
 
 
 
 
232
  submit = gr.Button("Submit")
233
  with gr.Column(scale=3):
234
  formated_result = gr.TextArea(
@@ -239,6 +250,7 @@ The performance of using the output from this demo for other model is not guaran
239
  submit.click(
240
  wrapper,
241
  inputs=[
 
242
  rating,
243
  artist,
244
  characters,
 
4
  import spaces
5
  import gradio as gr
6
  import torch
 
 
7
  from transformers import LlamaForCausalLM, LlamaTokenizer
8
 
9
  from kgen.generate import tag_gen
10
  from kgen.metainfo import SPECIAL, TARGET
11
 
12
 
13
+ MODEL_PATHS = ["KBlueLeaf/DanTagGen-alpha", "KBlueLeaf/DanTagGen-beta"]
14
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
15
  print(f"Using device: {DEVICE}")
16
 
17
 
 
111
 
112
 
113
  if __name__ == "__main__":
114
+ models = {
115
+ model_path: [
116
+ LlamaForCausalLM.from_pretrained(model_path).eval().half().to(DEVICE),
117
+ LlamaTokenizer.from_pretrained(model_path),
118
+ ]
119
+ for model_path in MODEL_PATHS
120
+ }
121
 
122
  @spaces.GPU
123
  def wrapper(
124
+ model: str,
125
  rating: str,
126
  artist: str,
127
  characters: str,
 
135
  escape_bracket: bool,
136
  temperature: float = 1.35,
137
  ):
138
+ text_model, tokenizer = models[model]
139
  yield from get_result(
140
  text_model,
141
  tokenizer,
 
155
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
156
  gr.Markdown("""# DanTagGen beta DEMO""")
157
  with gr.Accordion("Introduction and Instructions"):
158
+ gr.Markdown(
159
+ """
160
  #### What is this:
161
  DanTagGen(Danbooru Tag Generator) is a LLM model designed for generating Danboou Tags with provided informations.<br>
162
  It aims to provide user a more convinient way to make prompts for Text2Image model which is trained on Danbooru datasets.
 
178
  #### Notice
179
  The formated result use same format as what Kohaku-XL Delta used. <br>
180
  The performance of using the output from this demo for other model is not guaranteed.
181
+ """
182
+ )
183
  with gr.Row():
184
  with gr.Column(scale=4):
185
  with gr.Row():
 
204
  label="Target length",
205
  )
206
  with gr.Column(scale=2):
207
+ general = gr.TextArea(label="Input your general tags", lines=6)
208
  black_list = gr.TextArea(
209
+ label="tag Black list (seperated by comma)", lines=5
210
  )
211
  with gr.Row():
212
  width = gr.Slider(
 
235
  value=False,
236
  label="Escape bracket",
237
  )
238
+ model = gr.Dropdown(
239
+ list(models.keys()),
240
+ value=list(models.keys())[-1],
241
+ label="Model",
242
+ )
243
  submit = gr.Button("Submit")
244
  with gr.Column(scale=3):
245
  formated_result = gr.TextArea(
 
250
  submit.click(
251
  wrapper,
252
  inputs=[
253
+ model,
254
  rating,
255
  artist,
256
  characters,