MrDrmm commited on
Commit
2590709
·
verified ·
1 Parent(s): 3c6c4cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -37
app.py CHANGED
@@ -1,45 +1,22 @@
1
  import gradio as gr
2
- import os
3
  from model import models
4
- from multit2i import (
5
- load_models, infer_fn, infer_rand_fn, save_gallery,
6
  change_model, warm_model, get_model_info_md, loaded_models,
7
  get_positive_prefix, get_positive_suffix, get_negative_prefix, get_negative_suffix,
8
- get_recom_prompt_type, set_recom_prompt_preset, get_tag_type, randomize_seed, translate_to_en
9
- )
10
 
11
- # Устанавливаем максимальные значения
12
  max_images = 8
13
- MAX_SEED = 2**32 - 1
14
  load_models(models)
15
 
16
- # CSS для оформления
17
  css = """
18
  .model_info { text-align: center; }
19
  .output { width=112px; height=112px; max_width=112px; max_height=112px; !important; }
20
  .gallery { min_width=512px; min_height=512px; max_height=1024px; !important; }
21
  """
22
 
23
- # Функция установки HF_TOKEN
24
- def set_hf_token(hf_token):
25
- if hf_token:
26
- os.environ["HF_TOKEN"] = hf_token # Сохраняем токен в окружении
27
- return f"✅ HF_TOKEN установлен!", gr.update(value=hf_token, interactive=True)
28
- else:
29
- return "❌ Токен не введен!", gr.update(value="", interactive=True)
30
-
31
- # Основной интерфейс
32
  with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
33
-
34
- with gr.Tab("Settings"): # Вкладка для настройки HF_TOKEN
35
- gr.Markdown("### Настройки токена Hugging Face")
36
-
37
- hf_token_input = gr.Textbox(label="Введите HF Token", type="password", interactive=True)
38
- confirm_token = gr.Button("Активировать HF_TOKEN")
39
- token_status = gr.Markdown("🔴 HF_TOKEN не установлен")
40
-
41
- confirm_token.click(set_hf_token, inputs=[hf_token_input], outputs=[token_status, hf_token_input])
42
-
43
  with gr.Tab("Image Generator"):
44
  with gr.Row():
45
  with gr.Column(scale=10):
@@ -48,13 +25,13 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
48
  with gr.Accordion("Advanced options", open=False):
49
  neg_prompt = gr.Text(label="Negative Prompt", lines=1, max_lines=8, placeholder="")
50
  with gr.Row():
51
- width = gr.Slider(label="Width", maximum=2048, step=32, value=0)
52
- height = gr.Slider(label="Height", maximum=2048, step=32, value=0)
53
- steps = gr.Slider(label="Inference steps", maximum=100, step=1, value=0)
54
  with gr.Row():
55
- cfg = gr.Slider(label="Guidance scale", maximum=30.0, step=0.1, value=0)
56
- seed = gr.Slider(label="Seed", minimum=-1, maximum=MAX_SEED, step=1, value=-1)
57
- seed_rand = gr.Button("🎲 Randomize Seed", size="sm", variant="secondary")
58
  recom_prompt_preset = gr.Radio(label="Set Presets", choices=get_recom_prompt_type(), value="Common")
59
  with gr.Row():
60
  positive_prefix = gr.CheckboxGroup(label="Use Positive Prefix", choices=get_positive_prefix(), value=[])
@@ -69,10 +46,10 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
69
  run_button = gr.Button("Generate Image", variant="primary", scale=8)
70
  random_button = gr.Button("Random Model 🎲", variant="secondary", scale=3)
71
  stop_button = gr.Button('Stop', interactive=False, variant="stop", scale=1)
 
72
  with gr.Group():
73
  model_name = gr.Dropdown(label="Select Model", choices=list(loaded_models.keys()), value=list(loaded_models.keys())[0], allow_custom_value=True)
74
  model_info = gr.Markdown(value=get_model_info_md(list(loaded_models.keys())[0]), elem_classes="model_info")
75
-
76
  with gr.Column(scale=10):
77
  with gr.Group():
78
  with gr.Row():
@@ -158,9 +135,9 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
158
 
159
 
160
 
161
- demo.queue(default_concurrency_limit=240, max_size=240)
162
- demo.launch(max_threads=400, ssr_mode=True)
163
  # https://github.com/gradio-app/gradio/issues/6339
164
 
165
- demo.queue(concurrency_count=50)
166
  demo.launch()
 
1
  import gradio as gr
 
2
  from model import models
3
+ from multit2i import (load_models, infer_fn, infer_rand_fn, save_gallery,
 
4
  change_model, warm_model, get_model_info_md, loaded_models,
5
  get_positive_prefix, get_positive_suffix, get_negative_prefix, get_negative_suffix,
6
+ get_recom_prompt_type, set_recom_prompt_preset, get_tag_type, randomize_seed, translate_to_en)
7
+
8
 
 
9
  max_images = 8
10
+ MAX_SEED = 2**32-1
11
  load_models(models)
12
 
 
13
  css = """
14
  .model_info { text-align: center; }
15
  .output { width=112px; height=112px; max_width=112px; max_height=112px; !important; }
16
  .gallery { min_width=512px; min_height=512px; max_height=1024px; !important; }
17
  """
18
 
 
 
 
 
 
 
 
 
 
19
  with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
 
 
 
 
 
 
 
 
 
 
20
  with gr.Tab("Image Generator"):
21
  with gr.Row():
22
  with gr.Column(scale=10):
 
25
  with gr.Accordion("Advanced options", open=False):
26
  neg_prompt = gr.Text(label="Negative Prompt", lines=1, max_lines=8, placeholder="")
27
  with gr.Row():
28
+ width = gr.Slider(label="Width", info="If 0, the default value is used.", maximum=2048, step=32, value=0)
29
+ height = gr.Slider(label="Height", info="If 0, the default value is used.", maximum=2048, step=32, value=0)
30
+ steps = gr.Slider(label="Number of inference steps", info="If 0, the default value is used.", maximum=100, step=1, value=0)
31
  with gr.Row():
32
+ cfg = gr.Slider(label="Guidance scale", info="If 0, the default value is used.", maximum=30.0, step=0.1, value=0)
33
+ seed = gr.Slider(label="Seed", info="Randomize Seed if -1.", minimum=-1, maximum=MAX_SEED, step=1, value=-1)
34
+ seed_rand = gr.Button("Randomize Seed 🎲", size="sm", variant="secondary")
35
  recom_prompt_preset = gr.Radio(label="Set Presets", choices=get_recom_prompt_type(), value="Common")
36
  with gr.Row():
37
  positive_prefix = gr.CheckboxGroup(label="Use Positive Prefix", choices=get_positive_prefix(), value=[])
 
46
  run_button = gr.Button("Generate Image", variant="primary", scale=8)
47
  random_button = gr.Button("Random Model 🎲", variant="secondary", scale=3)
48
  stop_button = gr.Button('Stop', interactive=False, variant="stop", scale=1)
49
+
50
  with gr.Group():
51
  model_name = gr.Dropdown(label="Select Model", choices=list(loaded_models.keys()), value=list(loaded_models.keys())[0], allow_custom_value=True)
52
  model_info = gr.Markdown(value=get_model_info_md(list(loaded_models.keys())[0]), elem_classes="model_info")
 
53
  with gr.Column(scale=10):
54
  with gr.Group():
55
  with gr.Row():
 
135
 
136
 
137
 
138
+ #demo.queue(default_concurrency_limit=240, max_size=240)
139
+ #demo.launch(max_threads=400, ssr_mode=True)
140
  # https://github.com/gradio-app/gradio/issues/6339
141
 
142
+ #demo.queue(concurrency_count=50)
143
  demo.launch()