MrDrmm commited on
Commit
5e3d086
·
verified ·
1 Parent(s): 140aeb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -41
app.py CHANGED
@@ -45,48 +45,17 @@ models = [
45
  'Jonjew/NSFWMaster',
46
  ]
47
 
48
- # Загрузка моделей
49
- def load_fn(models):
50
- global models_load
51
- models_load = {}
52
- for model in models:
53
- try:
54
- models_load[model] = gr.load(f'models/{model}')
55
- except Exception as e:
56
- print(f"Failed to load model {model}: {e}")
57
- models_load[model] = gr.Interface(lambda txt: None, ['text'], ['image'])
58
-
59
- load_fn(models)
60
-
61
- num_models = len(models)
62
- default_models = models[:num_models]
63
-
64
- def extend_choices(choices):
65
- return choices + (num_models - len(choices)) * ['NA']
66
-
67
- def update_imgbox(choices):
68
- choices_plus = extend_choices(choices)
69
- return [gr.Image(None, label=m, visible=(m != 'NA'), elem_id="custom_image") for m in choices_plus]
70
-
71
- # Функция генерации
72
-
73
- def gen_fn(model_str, prompt, width, height):
74
- if model_str == 'NA' or model_str not in models_load:
75
- return None
76
- try:
77
- result = models_load[model_str](prompt)
78
- if isinstance(result, str):
79
- result = Image.open(result)
80
- if isinstance(result, Image.Image):
81
- result = result.resize((width, height))
82
- return result
83
- except Exception as e:
84
- print(f"Error generating image for model {model_str}: {e}")
85
- noise = str(randint(0, 9999999))
86
- return models_load[model_str](f'{prompt} {noise}')
87
-
88
-
89
 
 
 
 
 
 
 
 
 
 
90
 
91
 
92
  # Функция основного интерфейса
 
45
  'Jonjew/NSFWMaster',
46
  ]
47
 
48
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
+ max_images = 8
51
+ MAX_SEED = 2**32-1
52
+ load_models(models)
53
+
54
+ css = """
55
+ .model_info { text-align: center; }
56
+ .output { width=112px; height=112px; max_width=112px; max_height=112px; !important; }
57
+ .gallery { min_width=512px; min_height=512px; max_height=1024px; !important; }
58
+ """
59
 
60
 
61
  # Функция основного интерфейса