DigiP-AI commited on
Commit
9461ac9
·
verified ·
1 Parent(s): 72f9556

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -44
app.py CHANGED
@@ -15,14 +15,10 @@ import re
15
  from gradio_client import Client
16
  from fake_useragent import UserAgent
17
  import random
18
- from theme import theme
19
- from fastapi import FastAPI
20
 
21
- app = FastAPI()
22
- @app.get("/")
23
 
24
- def query(prompt, negative_prompt, task, steps=35, sampler="DPM++ 2M Karras", cfg_scale=7, seed=-1, width=896, height=1152):
25
- result = {prompt:"prompt", negative_prompt:"negative_prompt", task:"task", steps:"steps", sampler:"sampler", cfg_scale:print(result)}
26
  print(result)
27
  try:
28
  language = detect(prompt)
@@ -179,39 +175,36 @@ def mirror(image_output, scale_by, method, gfpgan, codeformer):
179
  img = Image.open(BytesIO(response2.content))
180
  return img
181
 
182
- examples = [
183
- "a beautiful woman with blonde hair and blue eyes",
184
- "a beautiful woman with brown hair and grey eyes",
185
- "a beautiful woman with black hair and brown eyes",
186
- ]
187
-
188
- # CSS to style the app
189
  css = """
190
- .gradio-container {background-color: MediumAquaMarine}
191
-
192
- footer {
193
- visibility: hidden;
 
 
 
 
 
 
 
 
 
 
 
194
  }
195
  """
196
 
197
- with gr.Blocks(css=css, theme=theme, fill_width= False) as app:
198
 
199
- with gr.Tab("Basic Settings"):
200
  with gr.Row():
201
- prompt = gr.Textbox(placeholder="Enter the image description...", show_label=True, label='Description of the image:', lines=3)
202
  with gr.Row():
203
- task = gr.Radio(interactive=True, value="Stable Diffusion XL 1.0", show_label=True, label="Model of neural network:", choices=['Stable Diffusion XL 1.0', 'Crystal Clear XL',
204
  'Juggernaut XL', 'DreamShaper XL',
205
  'SDXL Niji', 'Cinemax SDXL', 'NightVision XL',
206
  'Playground v2', 'Artigen v3'])
207
- gr.Examples(
208
- examples = examples,
209
- inputs = [prompt],
210
- )
211
-
212
-
213
-
214
- with gr.Tab("Extended settings"):
215
  with gr.Row():
216
  negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=True, label='Negative Prompt:', lines=3, value="[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry")
217
  with gr.Row():
@@ -224,31 +217,26 @@ with gr.Blocks(css=css, theme=theme, fill_width= False) as app:
224
  with gr.Row():
225
  seed = gr.Number(show_label=True, label="Seed:", minimum=-1, maximum=1000000, value=-1, step=1)
226
 
227
- with gr.Tab("Upscaling Settings"):
228
  with gr.Column():
229
  with gr.Row():
230
- scale_by = gr.Number(show_label=True, label="How many times to increase:", minimum=1, maximum=2, value=2, step=1)
231
  with gr.Row():
232
- method = gr.Dropdown(show_label=True, value="ESRGAN_4x", label="Algorithm to enlarge", choices=["ScuNET GAN", "SwinIR 4x", "ESRGAN_4x", "R-ESRGAN 4x+", "R-ESRGAN 4x+ Anime6B"])
233
  with gr.Column():
234
  with gr.Row():
235
- gfpgan = gr.Slider(show_label=True, label="Эффект GFPGAN (to improve the face)", minimum=0, maximum=1, value=0, step=0.1)
236
  with gr.Row():
237
- codeformer = gr.Slider(show_label=True, label="Effect CodeFormer (to improve the face)", minimum=0, maximum=1, value=0, step=0.1)
238
 
239
  with gr.Column():
240
- text_button = gr.Button("Generate image", variant='primary', elem_id="generate")
241
  with gr.Column():
242
  image_output = gr.Image(show_download_button=True, interactive=False, label='Результат:', elem_id='image_output', type='filepath')
243
- text_button.click(query, inputs=[prompt, negative_prompt, task, steps, sampler, cfg_scale, seed], outputs=image_output, concurrency_limit=48)
244
- clear_prompt =gr.Button("Clear 🗑️",variant="primary", elem_id="clear_button")
245
- clear_prompt.click(lambda: (None, None), None, [prompt, image_output], queue=False, show_api=False)
246
 
247
- img2img_b = gr.Button("Increase the image", variant='secondary')
248
- image_i2i = gr.Image(show_label=True, label='Increased image:')
249
  img2img_b.click(mirror, inputs=[image_output, scale_by, method, gfpgan, codeformer], outputs=image_i2i, concurrency_limit=48)
250
 
251
- app.queue(default_concurrency_limit=200, max_size=200) # <-- Sets up a queue with default parameters
252
- if __name__ == "__main__":
253
- app.launch()
254
-
 
15
  from gradio_client import Client
16
  from fake_useragent import UserAgent
17
  import random
 
 
18
 
 
 
19
 
20
+ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
21
+ result = {"prompt": prompt,"negative_prompt": negative_prompt,"task": task,"steps": steps,"sampler": sampler,"cfg_scale": cfg_scale,"seed": seed}
22
  print(result)
23
  try:
24
  language = detect(prompt)
 
175
  img = Image.open(BytesIO(response2.content))
176
  return img
177
 
 
 
 
 
 
 
 
178
  css = """
179
+ #generate {
180
+ width: 100%;
181
+ background: #e253dd !important;
182
+ border: none;
183
+ border-radius: 50px;
184
+ outline: none !important;
185
+ color: white;
186
+ }
187
+ #generate:hover {
188
+ background: #de6bda !important;
189
+ outline: none !important;
190
+ color: #fff;
191
+ }
192
+ #image_output {
193
+ height: 100% !important;
194
  }
195
  """
196
 
197
+ with gr.Blocks(css=css) as demo:
198
 
199
+ with gr.Tab("Базовые настройки"):
200
  with gr.Row():
201
+ prompt = gr.Textbox(placeholder="Введите описание изображения...", show_label=True, label='Описание изображения:', lines=3)
202
  with gr.Row():
203
+ task = gr.Radio(interactive=True, value="Stable Diffusion XL 1.0", show_label=True, label="Модель нейросети:", choices=['Stable Diffusion XL 1.0', 'Crystal Clear XL',
204
  'Juggernaut XL', 'DreamShaper XL',
205
  'SDXL Niji', 'Cinemax SDXL', 'NightVision XL',
206
  'Playground v2', 'Artigen v3'])
207
+ with gr.Tab("Расширенные настройки"):
 
 
 
 
 
 
 
208
  with gr.Row():
209
  negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=True, label='Negative Prompt:', lines=3, value="[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry")
210
  with gr.Row():
 
217
  with gr.Row():
218
  seed = gr.Number(show_label=True, label="Seed:", minimum=-1, maximum=1000000, value=-1, step=1)
219
 
220
+ with gr.Tab("Настройки апскейлинга"):
221
  with gr.Column():
222
  with gr.Row():
223
+ scale_by = gr.Number(show_label=True, label="Во сколько раз увеличить:", minimum=1, maximum=2, value=2, step=1)
224
  with gr.Row():
225
+ method = gr.Dropdown(show_label=True, value="ESRGAN_4x", label="Алгоритм увеличения", choices=["ScuNET GAN", "SwinIR 4x", "ESRGAN_4x", "R-ESRGAN 4x+", "R-ESRGAN 4x+ Anime6B"])
226
  with gr.Column():
227
  with gr.Row():
228
+ gfpgan = gr.Slider(show_label=True, label="Эффект GFPGAN (для улучшения лица)", minimum=0, maximum=1, value=0, step=0.1)
229
  with gr.Row():
230
+ codeformer = gr.Slider(show_label=True, label="Эффект CodeFormer (для улучшения лица)", minimum=0, maximum=1, value=0, step=0.1)
231
 
232
  with gr.Column():
233
+ text_button = gr.Button("Сгенерировать изображение", variant='primary', elem_id="generate")
234
  with gr.Column():
235
  image_output = gr.Image(show_download_button=True, interactive=False, label='Результат:', elem_id='image_output', type='filepath')
236
+ text_button.click(flip_text, inputs=[prompt, negative_prompt, task, steps, sampler, cfg_scale, seed], outputs=image_output, concurrency_limit=48)
 
 
237
 
238
+ img2img_b = gr.Button("Увеличить изображение", variant='secondary')
239
+ image_i2i = gr.Image(show_label=True, label='Увеличенное изображение:')
240
  img2img_b.click(mirror, inputs=[image_output, scale_by, method, gfpgan, codeformer], outputs=image_i2i, concurrency_limit=48)
241
 
242
+ demo.launch()