DazDin commited on
Commit
f6ee7c0
·
verified ·
1 Parent(s): f8ca6b0
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
  from random import randint
3
  from all_models import models
4
 
@@ -28,8 +29,21 @@ def update_imgbox(choices):
28
  def gen_fn(model_str, prompt):
29
  if model_str == 'NA':
30
  return None
31
- noise = str(randint(0, 9999999))
32
- return models_load[model_str](f'{prompt} {noise}')
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  def make_me():
35
  with gr.Row():
@@ -152,9 +166,11 @@ body {
152
  border: 1px solid #3b4252;
153
  background-color: #2d343f;
154
  border-radius: 4px;
155
- margin: 10px;
156
  max-width: 100%;
157
  box-sizing: border-box;
 
 
158
  }
159
  .custom_accordion {
160
  background-color: #2d3d4f;
@@ -217,5 +233,5 @@ body {
217
  with gr.Blocks(css=custom_css) as demo:
218
  make_me()
219
 
220
- demo.queue(concurrency_count=10)
221
  demo.launch()
 
1
  import gradio as gr
2
+ from io import BytesIO
3
  from random import randint
4
  from all_models import models
5
 
 
29
  def gen_fn(model_str, prompt):
30
  if model_str == 'NA':
31
  return None
32
+ noise = str(randint(0, 99999999))
33
+ result = models_load[model_str](f'{prompt} {noise}')
34
+
35
+ if isinstance(result, str):
36
+ response = requests.get(result)
37
+ img = Image.open(BytesIO(response.content))
38
+ elif isinstance(result, bytes):
39
+ img = Image.open(BytesIO(result))
40
+ else:
41
+ return None
42
+
43
+ buffered = BytesIO()
44
+ img.save(buffered, format="PNG")
45
+ img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
46
+ return f"data:image/png;base64,{img_str}"
47
 
48
  def make_me():
49
  with gr.Row():
 
166
  border: 1px solid #3b4252;
167
  background-color: #2d343f;
168
  border-radius: 4px;
169
+ margin: 20px;
170
  max-width: 100%;
171
  box-sizing: border-box;
172
+ width: 100%;
173
+ height: auto;
174
  }
175
  .custom_accordion {
176
  background-color: #2d3d4f;
 
233
  with gr.Blocks(css=custom_css) as demo:
234
  make_me()
235
 
236
+ demo.queue(concurrency_count=50)
237
  demo.launch()