burhansyam commited on
Commit
89a4326
·
verified ·
1 Parent(s): 461a96a

Upload 2 files

Browse files
Files changed (2) hide show
  1. all_models.py +11 -0
  2. app.py +74 -0
all_models.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ models = [
2
+ 'xey/sldr_flux_nsfw_v2-studio',
3
+ 'pimpilikipilapi1/fltax',
4
+ 'falanaja/Amateur-Photography',
5
+ 'seawolf2357/hanbok',
6
+ 'pimpilikipilapi1/bj',
7
+ 'burhansyam/difarina',
8
+ 'burhansyam/lalawidy',
9
+ 'burhansyam/davina',
10
+ 'burhansyam/bulsut',
11
+ ]
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from random import randint
4
+ from all_models import models
5
+
6
+ css_code = os.getenv("DazDinGo_CSS")
7
+
8
+ def load_fn(models):
9
+ global models_load
10
+ models_load = {}
11
+ for model in models:
12
+ if model not in models_load.keys():
13
+ try:
14
+ m = gr.load(f'models/{model}')
15
+ except Exception as error:
16
+ m = gr.Interface(lambda txt: None, ['text'], ['image'])
17
+ models_load.update({model: m})
18
+
19
+ load_fn(models)
20
+
21
+ num_models = len(models)
22
+ default_models = models[:num_models]
23
+
24
+ def extend_choices(choices):
25
+ return choices + (num_models - len(choices)) * ['NA']
26
+
27
+ def update_imgbox(choices):
28
+ choices_plus = extend_choices(choices)
29
+ return [gr.Image(None, label=m, visible=(m != 'NA'), elem_id="custom_image") for m in choices_plus]
30
+
31
+ def gen_fn(model_str, prompt):
32
+ if model_str == 'NA':
33
+ return None
34
+ noise = str(randint(0, 99999999))
35
+ return models_load[model_str](f'{prompt} {noise}')
36
+
37
+ def make_me():
38
+ with gr.Row():
39
+ with gr.Column(scale=4):
40
+ txt_input = gr.Textbox(label='Your prompt:', lines=4, container=False, elem_id="custom_textbox", placeholder="Prompt", height=250)
41
+
42
+ with gr.Column(scale=1):
43
+ gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
44
+ stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
45
+
46
+ def on_generate_click():
47
+ return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=True, elem_id="custom_stop_button")
48
+
49
+ def on_stop_click():
50
+ return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
51
+
52
+ gen_button.click(on_generate_click, inputs=None, outputs=[gen_button, stop_button])
53
+ stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
54
+
55
+ with gr.Row():
56
+ output = [gr.Image(label=m, width=512, max_height=768, elem_id="custom_image", show_label=True, interactive=False, show_share_button=False) for m in default_models]
57
+ current_models = [gr.Textbox(m, visible=False) for m in default_models]
58
+ for m, o in zip(current_models, output):
59
+ gen_event = gen_button.click(gen_fn, [m, txt_input], o)
60
+ stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
61
+
62
+ with gr.Accordion('Model selection', elem_id="custom_accordion"):
63
+ model_choice = gr.CheckboxGroup(models, label=f'{num_models} different models selected', value=default_models, interactive=True, elem_id="custom_checkbox_group")
64
+ model_choice.change(update_imgbox, model_choice, output)
65
+ model_choice.change(extend_choices, model_choice, current_models)
66
+
67
+ with gr.Row():
68
+ gr.HTML("")
69
+
70
+ with gr.Blocks(css=css_code) as demo:
71
+ make_me()
72
+
73
+ demo.queue(concurrency_count=50)
74
+ demo.launch()