GouriSankarPinaca commited on
Commit
6cf3b2a
1 Parent(s): 3ef7a47

like the hardwork

Browse files
Files changed (2) hide show
  1. .gitignore +1 -1
  2. app.py +86 -0
.gitignore CHANGED
@@ -1 +1 @@
1
- app.py
 
1
+ #app.py
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from random import randint
3
+ from all_models import models
4
+
5
+ def load_fn(models):
6
+ global models_load
7
+ models_load = {}
8
+
9
+ for model in models:
10
+ if model not in models_load.keys():
11
+ try:
12
+ m = gr.load(f'models/{model}')
13
+ except Exception as error:
14
+ m = gr.Interface(lambda txt: None, ['text'], ['image'])
15
+ models_load.update({model: m})
16
+
17
+ load_fn(models)
18
+
19
+ num_models = 6
20
+ default_models = models[:num_models]
21
+
22
+ def extend_choices(choices):
23
+ return choices + (num_models - len(choices)) * ['NA']
24
+
25
+ def update_imgbox(choices):
26
+ choices_plus = extend_choices(choices)
27
+ return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
28
+
29
+ def gen_fn(model_str, prompt, negative_prompt=None, image_style="Default"):
30
+ if model_str == 'NA':
31
+ return None
32
+ modified_prompt = prompt
33
+ if image_style != "Default":
34
+ modified_prompt += f", {image_style}"
35
+ if negative_prompt:
36
+ modified_prompt += f", not {negative_prompt}"
37
+ return models_load[model_str](modified_prompt)
38
+
39
+ with gr.Blocks() as demo:
40
+ with gr.Tab('The Dream'):
41
+ txt_input = gr.Textbox(label='Your prompt:', lines=4)
42
+
43
+ with gr.Accordion("Advanced Settings", open=False) as advanced_settings:
44
+ neg_prompt = gr.Textbox(label='Negative prompt (Optional):', placeholder='Enter undesirable attributes here', lines=2)
45
+ image_style = gr.Dropdown(label='Select Style', choices=["Default", "Realistic", "Portrait", "Anime"], value="Default")
46
+
47
+ gen_button = gr.Button('Generate up to 6 images in up to 2 minutes total')
48
+ stop_button = gr.Button('Stop', variant='secondary', interactive=False)
49
+
50
+ gen_button.click(lambda s: gr.update(interactive=True), None, stop_button, concurrency_limit=10)
51
+ gr.HTML(
52
+ """
53
+ <div style="text-align: center; max-width: 1200px; margin: 0 auto;">
54
+ <div>
55
+ <body>
56
+ <div class="center"><p style="margin-bottom: 10px; color: var(--body-text-color);">Scroll down to see more images and select models.</p>
57
+ </div>
58
+ </body>
59
+ </div>
60
+ </div>
61
+ """
62
+ )
63
+
64
+ with gr.Row():
65
+ output = [gr.Image(label=m, min_width=460) for m in default_models]
66
+ current_models = [gr.Textbox(m, visible=False) for m in default_models]
67
+
68
+ for m, o in zip(current_models, output):
69
+ gen_event = gen_button.click(gen_fn, [m, txt_input, neg_prompt, image_style], o, concurrency_limit=10)
70
+ stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
71
+
72
+ with gr.Accordion('Model selection'):
73
+ model_choice = gr.CheckboxGroup(models, label=f'Choose up to {num_models} different models from the best available!', value=default_models, interactive=True)
74
+ model_choice.change(update_imgbox, model_choice, output)
75
+ model_choice.change(extend_choices, model_choice, current_models)
76
+
77
+ with gr.Row():
78
+ gr.HTML(
79
+ """
80
+ <div class="footer">
81
+ <p>Have fun!
82
+ </p>
83
+ """
84
+ )
85
+
86
+ demo.launch(max_threads=200)