Yntec commited on
Commit
7aed1b6
1 Parent(s): d0bf66f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -12
app.py CHANGED
@@ -4,6 +4,12 @@ from all_models import models
4
 
5
  from externalmod import gr_Interface_load
6
 
 
 
 
 
 
 
7
  def load_fn(models):
8
  global models_load
9
  models_load = {}
@@ -11,9 +17,10 @@ def load_fn(models):
11
  for model in models:
12
  if model not in models_load.keys():
13
  try:
14
- m = gr_Interface_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
 
@@ -22,6 +29,7 @@ load_fn(models)
22
 
23
  num_models = 1
24
  default_models = models[:num_models]
 
25
 
26
 
27
 
@@ -61,8 +69,8 @@ with gr.Blocks() as demo:
61
  num_imagesone = gr.Slider(1, max_imagesone, value = max_imagesone, step = 1, label = 'Nobody gets to see this label so I can put here whatever I want!', visible = False)
62
 
63
  gen_button = gr.Button('Generate')
64
- stop_button = gr.Button('Stop', variant = 'secondary', interactive = False)
65
- gen_button.click(lambda s: gr.update(interactive = True), None, stop_button)
66
 
67
  with gr.Row():
68
  output = [gr.Image(label = '') for _ in range(max_imagesone)]
@@ -70,8 +78,8 @@ with gr.Blocks() as demo:
70
  for i, o in enumerate(output):
71
  img_in = gr.Number(i, visible = False)
72
  num_imagesone.change(lambda i, n: gr.update(visible = (i < n)), [img_in, num_imagesone], o, show_progress = False)
73
- gen_event = gen_button.click(lambda i, n, m, t: gen_fn(m, t) if (i < n) else None, [img_in, num_imagesone, model_choice, txt_input], o)
74
- stop_button.click(lambda s: gr.update(interactive = False), None, stop_button, cancels = [gen_event])
75
  with gr.Row():
76
  gr.HTML(
77
  """
@@ -88,8 +96,8 @@ with gr.Blocks() as demo:
88
  num_images = gr.Slider(1, max_images, value = max_images, step = 1, label = 'Number of images (if you want less than 6 decrease them slowly until they match the boxes below)')
89
 
90
  gen_button2 = gr.Button('Generate up to 6 images in up to 3 minutes total')
91
- stop_button2 = gr.Button('Stop', variant = 'secondary', interactive = False)
92
- gen_button2.click(lambda s: gr.update(interactive = True), None, stop_button2)
93
  gr.HTML(
94
  """
95
  <div style="text-align: center; max-width: 1200px; margin: 0 auto;">
@@ -108,8 +116,8 @@ with gr.Blocks() as demo:
108
  for i, o in enumerate(output2):
109
  img_i = gr.Number(i, visible = False)
110
  num_images.change(lambda i, n: gr.update(visible = (i < n)), [img_i, num_images], o, show_progress = False)
111
- gen_event2 = gen_button2.click(lambda i, n, m, t: gen_fnsix(m, t) if (i < n) else None, [img_i, num_images, model_choice2, txt_input2], o)
112
- stop_button2.click(lambda s: gr.update(interactive = False), None, stop_button2, cancels = [gen_event2])
113
  with gr.Row():
114
  gr.HTML(
115
  """
@@ -119,5 +127,5 @@ with gr.Blocks() as demo:
119
  """
120
  )
121
 
122
- demo.queue()
123
- demo.launch()
 
4
 
5
  from externalmod import gr_Interface_load
6
 
7
+ import asyncio
8
+ import os
9
+ from threading import RLock
10
+ lock = RLock()
11
+ HF_TOKEN = os.environ.get("HF_TOKEN") if os.environ.get("HF_TOKEN") else None # If private or gated models aren't used, ENV setting is unnecessary.
12
+
13
  def load_fn(models):
14
  global models_load
15
  models_load = {}
 
17
  for model in models:
18
  if model not in models_load.keys():
19
  try:
20
+ m = gr_Interface_load(f'models/{model}', hf_token=HF_TOKEN)
21
  except Exception as error:
22
+ print(error)
23
+ m = gr.Interface(lambda: None, ['text'], ['image'])
24
  models_load.update({model: m})
25
 
26
 
 
29
 
30
  num_models = 1
31
  default_models = models[:num_models]
32
+ inference_timeout = 600
33
 
34
 
35
 
 
69
  num_imagesone = gr.Slider(1, max_imagesone, value = max_imagesone, step = 1, label = 'Nobody gets to see this label so I can put here whatever I want!', visible = False)
70
 
71
  gen_button = gr.Button('Generate')
72
+ #stop_button = gr.Button('Stop', variant = 'secondary', interactive = False)
73
+ gen_button.click(lambda s: gr.update(interactive = True), None)
74
 
75
  with gr.Row():
76
  output = [gr.Image(label = '') for _ in range(max_imagesone)]
 
78
  for i, o in enumerate(output):
79
  img_in = gr.Number(i, visible = False)
80
  num_imagesone.change(lambda i, n: gr.update(visible = (i < n)), [img_in, num_imagesone], o, show_progress = False)
81
+ gen_event = gen_button.click(lambda i, n, m, t: gen_fn(m, t) if (i < n) else None, [img_in, num_imagesone, model_choice, txt_input], o, concurrency_limit=None, queue=False)
82
+ #stop_button.click(lambda s: gr.update(interactive = False), None, stop_button, cancels = [gen_event])
83
  with gr.Row():
84
  gr.HTML(
85
  """
 
96
  num_images = gr.Slider(1, max_images, value = max_images, step = 1, label = 'Number of images (if you want less than 6 decrease them slowly until they match the boxes below)')
97
 
98
  gen_button2 = gr.Button('Generate up to 6 images in up to 3 minutes total')
99
+ #stop_button2 = gr.Button('Stop', variant = 'secondary', interactive = False)
100
+ gen_button2.click(lambda s: gr.update(interactive = True), None)
101
  gr.HTML(
102
  """
103
  <div style="text-align: center; max-width: 1200px; margin: 0 auto;">
 
116
  for i, o in enumerate(output2):
117
  img_i = gr.Number(i, visible = False)
118
  num_images.change(lambda i, n: gr.update(visible = (i < n)), [img_i, num_images], o, show_progress = False)
119
+ gen_event2 = gen_button2.click(lambda i, n, m, t: gen_fnsix(m, t) if (i < n) else None, [img_i, num_images, model_choice2, txt_input2], o, concurrency_limit=None, queue=False)
120
+ #stop_button2.click(lambda s: gr.update(interactive = False), None, stop_button2, cancels = [gen_event2])
121
  with gr.Row():
122
  gr.HTML(
123
  """
 
127
  """
128
  )
129
 
130
+ demo.queue(default_concurrency_limit=200, max_size=200)
131
+ demo.launch(show_api=False, max_threads=400)