WiNE-iNEFF commited on
Commit
730c2ca
·
1 Parent(s): c1f0376

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -1
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import random
3
  from time import time, ctime
4
 
5
- def promptgen(choice, num, artist):
6
  t = time()
7
  print(ctime(t))
8
 
@@ -30,6 +30,40 @@ def promptgen(choice, num, artist):
30
  print(', '.join(set(generated)) + '\n')
31
  return ', '.join(set(generated))
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  demo = gr.Blocks()
34
 
35
  with demo:
 
2
  import random
3
  from time import time, ctime
4
 
5
+ def promptgen2(choice, num, artist):
6
  t = time()
7
  print(ctime(t))
8
 
 
30
  print(', '.join(set(generated)) + '\n')
31
  return ', '.join(set(generated))
32
 
33
+ def promptgen(choice, num, artist):
34
+ try:
35
+ gen_prompt = open('gen_prompt.txt').read().splitlines()
36
+ except:
37
+ pass
38
+ t = time()
39
+ print(ctime(t))
40
+
41
+ if choice == "Prompt Generator v0.1(Better quality)":
42
+ prompt = open('pr1.txt').read().splitlines()
43
+ elif choice == "Prompt Generator v0.2(More tags)":
44
+ prompt = open('pr2.txt').read().splitlines()
45
+
46
+ if int(num) < 1 or int(num) > 20:
47
+ num = 10
48
+
49
+ if int(artist) < 0 or int(artist) > 40:
50
+ artist = 2
51
+
52
+ vocab = len(prompt)
53
+ generated = []
54
+ artists_num = 0
55
+ with open('gen_prompt.txt', 'wb') as f:
56
+ while len(sorted(set(generated), key=lambda d: generated.index(d))) < num:
57
+ rand = random.randint(0, vocab)
58
+ if prompt[rand-1].startswith('art by') and artists_num < artist:
59
+ artists_num +=1
60
+ generated.append(prompt[rand-1])
61
+ elif not prompt[rand-1].startswith('art by'):
62
+ generated.append(prompt[rand-1])
63
+ print(', '.join(set(generated)) + '\n')
64
+ f.write(f'{ctime(t)} - {', '.join(set(generated))}')
65
+ return ', '.join(set(generated))
66
+
67
  demo = gr.Blocks()
68
 
69
  with demo: