DazDin commited on
Commit
f9be2b2
·
verified ·
1 Parent(s): 7d71c52

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -77
app.py DELETED
@@ -1,77 +0,0 @@
1
- import gradio as gr
2
- from random import randint
3
- from all_models import models
4
- from datetime import datetime
5
-
6
- def get_current_time():
7
- now = datetime.now()
8
- current_time = now2.strftime("%Y-%m-%d %H:%M:%S")
9
- ki = f'{kii} {current_time}'
10
- return ki
11
-
12
- def load_fn(models):
13
- global models_load
14
- models_load = {}
15
- for model in models:
16
- if model not in models_load.keys():
17
- try:
18
- m = gr.load(f'models/{model}')
19
- except Exception as error:
20
- m = gr.Interface(lambda txt: None, ['text'], ['image'])
21
- models_load.update({model: m})
22
-
23
- load_fn(models)
24
-
25
- num_models = len(models)
26
- default_models = models[:num_models]
27
-
28
- def extend_choices(choices):
29
- return choices + (num_models - len(choices)) * ['NA']
30
-
31
- def update_imgbox(choices):
32
- choices_plus = extend_choices(choices)
33
- return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
34
-
35
- def gen_fn(model_str, prompt, negative_prompt):
36
- if model_str == 'NA':
37
- return None
38
- noise = str(randint(0, 9999))
39
- full_prompt = f"{prompt} --negative-prompt {negative_prompt}" if negative_prompt else prompt
40
- return models_load[model_str](full_prompt + f" {noise}")
41
-
42
- def make_me():
43
- with gr.Row():
44
- txt_input = gr.Textbox(label='Your prompt:', lines=2, width=800, max_height=30)
45
- neg_txt_input = gr.Textbox(label='Negative prompt:', lines=2, width=800, max_height=30)
46
- gen_button = gr.Button('Generate images', width=30, height=30)
47
- stop_button = gr.Button('Stop', variant='secondary', interactive=False, width=30, height=30)
48
- gen_button.click(lambda s: gr.update(interactive=True), None, stop_button)
49
- gr.HTML("""
50
- <div style="text-align: center; max-width: 100%; margin: 0 auto;">
51
- <body>
52
- </body>
53
- </div>
54
- """)
55
- with gr.Row():
56
- output = [gr.Image(label=m, min_width=250, height=250) 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, neg_txt_input], o)
60
- stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
61
- with gr.Accordion('Model selection'):
62
- model_choice = gr.CheckboxGroup(models, label=f' {num_models} different models selected', value=default_models, multiselect=True, max_choices=num_models, interactive=True, filterable=False)
63
- model_choice.change(update_imgbox, model_choice, output)
64
- model_choice.change(extend_choices, model_choice, current_models)
65
- with gr.Row():
66
- gr.HTML()
67
-
68
- js_code = """
69
- console.log('ghgh');
70
- """
71
-
72
- with gr.Blocks(css="div.float.svelte-1mwvhlq { position: absolute; top: var(--block-label-margin); left: var(--block-label-margin); background: none; border: none;}") as demo:
73
- gr.Markdown("<script>" + js_code + "</script>")
74
- make_me()
75
-
76
- demo.queue(concurrency_count=100)
77
- demo.launch()