gustproof commited on
Commit
2b9e61d
1 Parent(s): c3fd84a

More stuff

Browse files
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ __pycache__
2
+ *.zip
actions.txt CHANGED
The diff for this file is too large to render. See raw diff
 
actions_general.txt ADDED
The diff for this file is too large to render. See raw diff
 
actions_sensitive.txt ADDED
The diff for this file is too large to render. See raw diff
 
app.py CHANGED
@@ -5,34 +5,49 @@ from random import sample
5
 
6
  with open("meta.json") as f:
7
  meta = json.load(f)
 
 
 
8
  with open("tag2cat.json") as f:
9
  tag2cat = json.load(f)
10
- f = lambda cat: [
11
- ", ".join(
12
- t
13
- for t in (tag.replace("_", " ") for tag in e["tag_string_general"].split())
14
- if tag2cat.get(t, "") == cat
15
- )
16
- for e in meta
17
- ]
18
- l = [f(c) for c in "Character Outfit Action Scene".split()]
19
 
20
 
21
- def do():
22
- idxs = sample(range(len(meta)), 4)
23
- parts = [ll[idx] for ll, idx in zip(l, idxs)]
 
 
 
 
 
 
 
 
 
24
  return (",\n".join(parts),) + tuple(
25
  _
26
  for p, idx in zip(parts, idxs)
27
  for _ in (
28
- f"{p} ([danbooru post](https://danbooru.donmai.us/posts/{meta[idx]['id']}))",
29
- f'![]({meta[idx]["large_file_url"]})',
30
  )
31
  )
32
 
33
 
34
  with gr.Blocks() as demo:
35
  with gr.Row():
 
 
 
 
 
36
  button = gr.Button("Get Random Prompt", variant="primary")
37
  with gr.Row():
38
  joined = gr.Text(label="generated prompt", show_copy_button=True)
@@ -48,7 +63,7 @@ with gr.Blocks() as demo:
48
  img_scene = gr.Markdown()
49
  button.click(
50
  do,
51
- [],
52
  [
53
  joined,
54
  text_char,
 
5
 
6
  with open("meta.json") as f:
7
  meta = json.load(f)
8
+
9
+ meta_s = [x for x in meta if x["rating"] == "s"]
10
+ meta_g = [x for x in meta if x["rating"] == "g"]
11
  with open("tag2cat.json") as f:
12
  tag2cat = json.load(f)
13
+ f = lambda cat, e: ", ".join(
14
+ t
15
+ for t in (tag.replace("_", " ") for tag in e["tag_string_general"].split())
16
+ if tag2cat.get(t, "") == cat
17
+ )
18
+
19
+ cats = "Character Outfit Action Scene".split()
 
 
20
 
21
 
22
+ def do(ratings):
23
+ if not ratings:
24
+ raise gr.Error("Please select at least one of the ratings")
25
+ m = (
26
+ meta_g
27
+ if ratings[0] == "General"
28
+ else meta_s
29
+ if ratings[0] == "Sensitive"
30
+ else meta
31
+ )
32
+ idxs = sample(range(len(m)), 4)
33
+ parts = [f(cat, m[idx]) for cat, idx in zip(cats, idxs)]
34
  return (",\n".join(parts),) + tuple(
35
  _
36
  for p, idx in zip(parts, idxs)
37
  for _ in (
38
+ f"{p} ([danbooru post](https://danbooru.donmai.us/posts/{m[idx]['id']}))",
39
+ f'![]({m[idx]["large_file_url"]})',
40
  )
41
  )
42
 
43
 
44
  with gr.Blocks() as demo:
45
  with gr.Row():
46
+ ratings = gr.CheckboxGroup(
47
+ ["General", "Sensitive"],
48
+ label="Allowed ratings",
49
+ value=["General", "Sensitive"],
50
+ )
51
  button = gr.Button("Get Random Prompt", variant="primary")
52
  with gr.Row():
53
  joined = gr.Text(label="generated prompt", show_copy_button=True)
 
63
  img_scene = gr.Markdown()
64
  button.click(
65
  do,
66
+ [ratings],
67
  [
68
  joined,
69
  text_char,
characters.txt CHANGED
The diff for this file is too large to render. See raw diff
 
characters_general.txt ADDED
The diff for this file is too large to render. See raw diff
 
characters_sensitive.txt ADDED
The diff for this file is too large to render. See raw diff
 
meta.json CHANGED
The diff for this file is too large to render. See raw diff
 
outfits.txt CHANGED
The diff for this file is too large to render. See raw diff
 
outfits_general.txt ADDED
The diff for this file is too large to render. See raw diff
 
outfits_sensitive.txt ADDED
The diff for this file is too large to render. See raw diff
 
scenes.txt CHANGED
The diff for this file is too large to render. See raw diff
 
scenes_general.txt ADDED
The diff for this file is too large to render. See raw diff
 
scenes_sensitive.txt ADDED
The diff for this file is too large to render. See raw diff
 
tag2cat.json CHANGED
The diff for this file is too large to render. See raw diff