lovelyai999 commited on
Commit
cbbbc7e
·
verified ·
1 Parent(s): e8e1967

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +321 -0
app.py ADDED
@@ -0,0 +1,321 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ try:
3
+ import google.colab
4
+ IN_COLAB = True
5
+ from google.colab import drive
6
+ from google.colab import output
7
+ drive.mount('/gdrive')
8
+ Gbase="/gdrive/MyDrive/generate/"
9
+ cache_dir="/gdrive/MyDrive/hf/"
10
+ import sys
11
+ sys.path.append(Gbase)
12
+ except:
13
+ IN_COLAB = False
14
+ Gbase="./generate/"
15
+ cache_dir="./hf/"
16
+
17
+ import time
18
+ hexStamp=lambda :hex(time.time_ns())[2:]
19
+ from women1 import randomAction,randomWoman,Woman,woman_description,womanPrompt,ToWomanPrompt,WomanFromString,Translator,TranslatorS,TranslatorC2E,womanPromptUI
20
+ from man import randomActionMan,randomMan,Man,man_description,manPrompt,ToManPrompt,ManFromString,manPromptUI,randManWoman
21
+ from pets import randomActionAnimal,randomAnimal,Animal,pet_description,animalPrompt,ToAnimalPrompt,AnimalFromString,animalPromptUI,randAnimalWoman,randAnimalMan
22
+ from places import randomActionPlace,randomPlace,Place,place_description,placePrompt,ToPlacePrompt,PlaceFromString,placePromptUI
23
+
24
+ from fileDict3 import FileDict
25
+ from fileSQL3 import FileSQL3
26
+
27
+
28
+
29
+
30
+
31
+ if IN_COLAB:
32
+ output_dir=os.path.join (Gbase ,output_dir)
33
+ else:Gbase=""
34
+ os.makedirs(output_dir, exist_ok=True)
35
+
36
+
37
+
38
+
39
+ import gradio as gr
40
+ from gradio.context import Context
41
+ from gradio import Request
42
+
43
+
44
+ def persist(component):
45
+ sessions = {}
46
+
47
+ def resume_session(value, request: Request):
48
+ return sessions.get(request.username, value)
49
+
50
+ def update_session(value, request: Request):
51
+ sessions[request.username] = value
52
+
53
+ Context.root_block.load(resume_session, inputs=[component], outputs=component)
54
+ component.change(update_session, inputs=[component])
55
+
56
+ return component
57
+
58
+
59
+ sampPrompts=[
60
+ "A beautiful young office lady with blonde luxurious long hair and blue beautiful eyes,clear fine eyes , beautiful black pupil , phantom eyebrows,bloom shiny skin , curvaceous hot body ,casual wear,lardge breasts , eyes contact , confident , determined .",
61
+ "A sweet pretty woman with blonde luxurious hair and blue bright eyes,curvaceous hot body , lardge breasts , shiny bloom skin ,romantic .",
62
+ "A beautiful young office lady with black luxurious short hair and golden beautiful eyes,clear fine eyes , beautiful black pupil , phantom eyebrows,bloom shiny skin , curvaceous hot body ,elegant wear,lardge breasts , eyes contact , confident , determined .",
63
+ "A beautiful young office lady with golden vogue short hair and blue beautiful eyes,clear fine eyes , beautiful black pupil , phantom eyebrows,oily shiny skin , curvaceous hot body ,casual wear , eyes contact , confident , determined .",
64
+ "A beautiful slim girl with black luxurious hair and golden beautiful #eyes,clear fine eyes , beautiful black pupil , phantom eyebrows,oily smoothly skin , curvaceous hot body ,vogue wear , eyes contact , confident , determined .",
65
+ "A beautiful slim girl with blonde luxurious hair and blue beautiful eyes,clear fine eyes , beautiful golden pupil , phantom eyebrows,oily shiny skin , curvaceous hot body , eyes contact , confident , determined .",
66
+ "A beautiful slim girl with black luxurious hair and golden beautiful eyes,clear fine eyes , beautiful black pupil , phantom eyebrows,oily smoothly skin , curvaceous hot body ,vogue wear , eyes contact , confident , determined .",
67
+ "Create an image of a stunning woman with flowing black hair, captivating eyes, and an enchanting smile. She radiates elegance and confidence, and her beauty is mesmerizing. The background complements her features, enhancing her allure. The image captures her in a moment of grace and poise, expressing her unique charm and vibrant personality.",
68
+ "Create an image of a stunning woman with flowing blonde hair, captivating blue eyes, and an enchanting smile. She radiates elegance and confidence, and her beauty is mesmerizing. The background complements her features, enhancing her allure. The image captures her in a moment of grace and poise, expressing her unique charm and vibrant personality.",
69
+ "A beautiful slim girl with blonde luxurious hair and blue bright eyes,clear fine eyes ,beautiful blue eyes , phantom eyebrows,oily shiny skin , curvaceous hot body , eyes contact , confident , determined ,from side ,smile .",
70
+ "A beautiful slim girl with blonde luxurious hair and blue bright eyes , phantom eyebrows,oily shiny skin , beautiful bright eyes , , curvaceous hot body , eyes contact , confident , determined ,from side .,smile . " ,
71
+ "A beautiful slim girl with blonde luxurious hair and blue bright eyes , phantom eyebrows,oily shiny skin , beautiful bright eyes , curvaceous hot body , eyes contact , confident , determined ,from side ,smile .",
72
+ "A beautiful slim girl with blonde luxurious hair and blue bright eyes , phantom eyebrows,oily shiny skin , beautiful bright eyes , , curvaceous hot body , eyes contact , confident , determined ,from side .,smile . " ,
73
+ "A beautiful office lady with black hair and red eyes , phantom eyebrows,oily shiny skin , beautiful bright eyes , stylish vogue hair , curvaceous hot body , eyes contact , confident , determined ,from side . " ,
74
+ "A pretty young office woman , beautiful blue bright eyes ,lardge breasts , smile , beautiful face .",
75
+ "A very beautiful woman, shiny blonde hair, deep blue bright eyes, perfect figure,, hot clothing , smooth and shiny skin,lardge breasts, fantastic body,very beautiful perfect face,from side,eye contact .",
76
+ ]
77
+ promptIndex=0
78
+
79
+ def initPrompt():
80
+ global Gbase,sampPrompts
81
+ pPath=os.path.join(Gbase ,"mypromts.txt")
82
+ if os.path.exists (pPath):
83
+ sampPrompts=json.load(open(pPath))
84
+ else:
85
+ with open(pPath,"w" ) as jFile:json.dump(sampPrompts,jFile)
86
+
87
+ def savePrompt(p):
88
+ global Gbase,sampPrompts,promptIndex
89
+ initPrompt()
90
+ if promptIndex==-1:
91
+ sampPrompts.insert(0,p)
92
+ promptIndex=0
93
+ else:sampPrompts[promptIndex]=p
94
+ pPath=os.path.join(Gbase ,"mypromts.txt")
95
+ with open(pPath,"w" ) as jFile:
96
+ json.dump(sampPrompts,jFile)
97
+ return "saved"
98
+ def deletePrompt(p):
99
+ global Gbase,sampPrompts,promptIndex
100
+ if promptIndex==-1:
101
+ promptIndex=0
102
+ return sampPrompts[0]
103
+ try: sampPrompts.pop(sampPrompts.index(p))
104
+ except:pass
105
+ pPath=os.path.join(Gbase ,"mypromts.txt")
106
+ with open(pPath,"w" ) as jFile:
107
+ json.dump(sampPrompts,jFile)
108
+ return sampPrompts[promptIndex]
109
+
110
+
111
+ initPrompt()
112
+ currentWoman=randomWoman()
113
+ def randPrompt():
114
+ global promptIndex
115
+ promptIndex=-1
116
+ return randomWoman()
117
+ def randPromptUI():
118
+ global promptIndex,currentWoman
119
+ promptIndex=-1
120
+ w=WomanFromString(str(randomWoman()))
121
+ currentWoman=w
122
+ return str(w)
123
+ def randPromptMan():
124
+ global promptIndex
125
+ promptIndex=-1
126
+ return randomMan()
127
+
128
+ def randPromptAnimal():
129
+ global promptIndex
130
+ promptIndex=-1
131
+ return randomAnimal()
132
+ def randPromptPlace():
133
+ global promptIndex
134
+ promptIndex=-1
135
+ return randomPlace()
136
+
137
+
138
+ def randPromptManWoman():
139
+ global promptIndex
140
+ promptIndex=-1
141
+ return randManWoman()
142
+
143
+ def randPromptAnimalWoman():
144
+ global promptIndex
145
+ promptIndex=-1
146
+ return randAnimalWoman()
147
+
148
+ def randPromptAnimalMan():
149
+ global promptIndex
150
+ promptIndex=-1
151
+ return randAnimalMan()
152
+
153
+ def randPromptUIman():
154
+ global promptIndex,currentMan
155
+ promptIndex=-1
156
+ w=ManFromString(str(randomMan()))
157
+ currentMan=w
158
+ return str(w)
159
+
160
+ def randPromptUIplace():
161
+ global promptIndex,currentPlace
162
+ promptIndex=-1
163
+ w=PlaceFromString(str(randomPlace()))
164
+ currentPlace=w
165
+ return str(w)
166
+ def randPromptUIAnimal():
167
+ global promptIndex,currentAnimal
168
+ promptIndex=-1
169
+ w=AnimalFromString(str(randomAnimal()))
170
+ currentAnimal=w
171
+ return str(w)
172
+
173
+ def nextPrompt():
174
+ global promptIndex
175
+ promptIndex+=1
176
+ if promptIndex>=len(sampPrompts):promptIndex=0
177
+ return sampPrompts[promptIndex]
178
+
179
+ def previousPrompt():
180
+ global promptIndex
181
+ promptIndex-=1
182
+ if promptIndex<0:promptIndex=0
183
+ return sampPrompts[promptIndex]
184
+
185
+ def textToConfig(s):
186
+ w=WomanFromString(s)
187
+ return [w.character,w.eye_color,w.hair_style,w.hair_color,w.dress_styles,w.skin,w.body,w.breast_size,w.hip_measurements,w.action,w.additional,w.dress_upper]
188
+
189
+ def restConfig():return ["random"]*12
190
+ prompt=sampPrompts[0]
191
+ generator=torch.Generator(device=device)
192
+ generator.initial_seed()
193
+ if seed==-1:generator.manual_seed(seed)
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+ def changeRandomActions(b):
203
+ global randomActions
204
+ randomActions=b
205
+ return randomActions
206
+
207
+ def changeRandomActionsMan(b):
208
+ global randomActionsMan
209
+ randomActionsMan=b
210
+ return randomActionsMan
211
+
212
+
213
+
214
+
215
+
216
+
217
+ css=""".gradio-container {max-width: 544px !important}
218
+
219
+ """
220
+ css1="""
221
+ img {
222
+ opacity: 0; /* Optional: Initial hidden state */
223
+ }
224
+
225
+ img[loading="lazy"] {
226
+ opacity: 1; /* Optional: Show the image when it becomes visible */
227
+ }
228
+ """
229
+
230
+ with gr.Blocks(title="Images Prompts Generator", css=css) as demo:
231
+
232
+ with gr.Row():
233
+ with gr.Column():
234
+ textbox = persist(gr.Textbox(show_label=True , label ="prompt",show_copy_button=True ))
235
+ genWoman= gr.Button(value="Woman")
236
+ toConfig= gr.Button(value="To config")
237
+ bRestConfig= gr.Button(value="Rest config")
238
+ rptsP = gr.Button(value="Previous")
239
+ rpts = gr.Button(value="Next")
240
+ rptsRandom = gr.Button(value="RandomWoman")
241
+ rptsRandomMan = gr.Button(value="RandomMan")
242
+ rptsRandomAnimal= gr.Button(value="RandomAnimal")
243
+ rptsRandomManWoman= gr.Button(value="Random Man+Woman ")
244
+ rptsRandomAnimalWoman= gr.Button(value="Random Animal+Woman ")
245
+ rptsRandomAnimalMan= gr.Button(value="Random Animal+Man")
246
+ rptsRandomPlace= gr.Button(value="Random Place ")
247
+ rptsSave = gr.Button(value="Save")
248
+ rptsDelete = gr.Button(value="Delete")
249
+ character= persist(gr.Dropdown(woman_description["character"],label="character",value ="None",allow_custom_value=True ,show_label=True))
250
+ eye_color= persist(gr.Dropdown(woman_description["eye_color"],label="eye_color",value ="None" ,allow_custom_value=True,show_label=True))
251
+ hair_style= persist(gr.Dropdown(woman_description["hair_style"],label="hair_style",value ="None" ,allow_custom_value=True,show_label=True))
252
+ hair_color= persist(gr.Dropdown(woman_description["hair_color"],label="hair_color",value ="None" ,allow_custom_value=True,show_label=True))
253
+ dress_upper= persist(gr.Dropdown(woman_description["dress_upper"][:50],label="dress_upper",value ="None" ,allow_custom_value=True,show_label=True))
254
+ dress_styles= persist(gr.Dropdown(woman_description["dress_styles"][:50],label="dress_styles",value ="None" ,allow_custom_value=True,show_label=True))
255
+ skinT= persist(gr.Dropdown(woman_description["skin"],label="skin",value ="None" ,allow_custom_value=True,show_label=True))
256
+ bodyT= persist(gr.Dropdown(woman_description["body"],label="body",value ="None" ,allow_custom_value=True,show_label=True))
257
+ breast_size= persist(gr.Dropdown(woman_description["breast_size"],label="breast_size",value ="None" ,allow_custom_value=True,show_label=True))
258
+ hip_measurements= persist(gr.Dropdown(woman_description["hip_measurements"],label="hip_measurements",value ="None" ,allow_custom_value=True,show_label=True))
259
+ actionT= persist(gr.Dropdown(woman_description["action"][:50],label="action",value ="None" ,allow_custom_value=True,show_label=True))
260
+ additionalT= persist(gr.Dropdown(woman_description["additional"],label="additional",value ="None" ,allow_custom_value=True,show_label=True))
261
+ clearTask.click(fn=endTasks)
262
+ runTask.click(fn=generateDir,
263
+ inputs=[textbox,text_neg,
264
+ img,
265
+ istr,
266
+ iwidth,iheight,
267
+ isteps,
268
+ igs,
269
+ ign,
270
+ iseed,
271
+ ioutputDir,isoureceDir,iStartIndex
272
+ ] )
273
+ rptsP.click(fn=previousPrompt,outputs=textbox)
274
+ genWoman.click(fn=womanPromptUI,inputs=[ character, eye_color , hair_style , hair_color , dress_styles , skinT , bodyT , breast_size , hip_measurements , actionT , additionalT,dress_upper],outputs=textbox)
275
+ rptsRandom.click(fn=randPromptUI,outputs=textbox)
276
+ rptsRandomMan.click(fn=randPromptUIman
277
+ ,outputs=textbox)
278
+ rptsRandomManWoman.click(fn=randPromptManWoman
279
+ ,outputs=textbox)
280
+
281
+ rptsRandomAnimal.click(fn=randPromptUIAnimal
282
+ ,outputs=textbox)
283
+ rptsRandomAnimalWoman.click(fn=randPromptAnimalWoman
284
+ ,outputs=textbox)
285
+ rptsRandomAnimalMan.click(fn=randPromptAnimalMan
286
+ ,outputs=textbox)
287
+ rptsRandomPlace.click(fn=randPromptPlace
288
+ ,outputs=textbox)
289
+ bRandomActionMan.change(fn=changeRandomActionsMan,inputs=bRandomActionMan,outputs=bRandomActionMan)
290
+ bRandomAction.change(fn=changeRandomActions,inputs=bRandomAction,outputs=bRandomAction)
291
+ bRestConfig.click(fn=restConfig,outputs=[ character, eye_color , hair_style , hair_color , dress_styles , skinT , bodyT , breast_size , hip_measurements , actionT , additionalT,dress_upper] )
292
+ toConfig.click(fn=textToConfig,inputs=textbox,outputs=[ character, eye_color , hair_style , hair_color , dress_styles , skinT , bodyT , breast_size , hip_measurements , actionT , additionalT,dress_upper] )
293
+ rpts.click(fn=nextPrompt,outputs=textbox)
294
+
295
+ rptsSave.click(fn=savePrompt,inputs=textbox)
296
+ rptsDelete.click(fn=deletePrompt,inputs=textbox ,outputs=textbox)
297
+ button.click(fn=queTask,
298
+ inputs=[textbox,text_neg,
299
+ img,
300
+ istr,
301
+ iwidth,iheight,
302
+ isteps,
303
+ igs,
304
+ ign,
305
+ iseed,ioutputDir],
306
+ )
307
+ bDoSample.click(fn=doSample,
308
+ inputs=[textbox,text_neg,
309
+ img,
310
+ istr,
311
+ iwidth,iheight,
312
+ isteps,
313
+ igs,
314
+ ign,
315
+ iseed,ioutputDir],
316
+ )
317
+ bLora.click(fn=fuseLora,inputs=iLora)
318
+
319
+
320
+
321
+ demo.launch()