G-Rost commited on
Commit
9180ce7
1 Parent(s): c160f3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -8
app.py CHANGED
@@ -3,7 +3,6 @@ import numpy as np
3
  import random
4
  from diffusers import DiffusionPipeline
5
  import torch
6
-
7
  import time
8
  import psutil
9
 
@@ -42,7 +41,7 @@ def generate_image(prompt, negative_prompt, seed, randomize_seed, width, height,
42
  if not prompt:
43
  raise gr.Error("Будь ласка, введіть опис для зображення.")
44
 
45
- torch.set_num_threads(MAX_THREADS) # Set the maximum number of threads
46
 
47
  pipe = load_pipeline(MODEL_OPTIONS[model_choice])
48
 
@@ -70,11 +69,30 @@ def generate_image(prompt, negative_prompt, seed, randomize_seed, width, height,
70
 
71
  return images, f"Час генерації: {generation_time:.2f} секунд"
72
 
73
- # ... (Gradio interface remains the same)
74
-
75
- generation_time = end_time - start_time
76
-
77
- return images, f"Час генерації: {generation_time:.2f} секунд"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
  run_button = gr.Button("Згенерувати")
80
  gallery = gr.Gallery(label="Згенеровані зображення")
@@ -83,5 +101,8 @@ def generate_image(prompt, negative_prompt, seed, randomize_seed, width, height,
83
  run_button.click(
84
  fn=generate_image,
85
  inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, num_images, model_choice],
86
- outputs=[gallery, status_text], # Output both the gallery and status text
87
  )
 
 
 
 
3
  import random
4
  from diffusers import DiffusionPipeline
5
  import torch
 
6
  import time
7
  import psutil
8
 
 
41
  if not prompt:
42
  raise gr.Error("Будь ласка, введіть опис для зображення.")
43
 
44
+ torch.set_num_threads(MAX_THREADS)
45
 
46
  pipe = load_pipeline(MODEL_OPTIONS[model_choice])
47
 
 
69
 
70
  return images, f"Час генерації: {generation_time:.2f} секунд"
71
 
72
+ with gr.Blocks() as demo:
73
+ with gr.Row():
74
+ with gr.Column(scale=5):
75
+ prompt = gr.Textbox(label="Опис зображення")
76
+ negative_prompt = gr.Textbox(label="Негативний опис", value="")
77
+ with gr.Column(scale=1):
78
+ model_choice = gr.Radio(
79
+ choices=list(MODEL_OPTIONS.keys()),
80
+ label="Якість моделі",
81
+ value=list(MODEL_OPTIONS.keys())[0],
82
+ )
83
+ with gr.Row():
84
+ seed = gr.Slider(label="Seed", minimum=0, maximum=1000000, step=1, value=42)
85
+ randomize_seed = gr.Checkbox(label="Випадковий Seed", value=True)
86
+
87
+ with gr.Row():
88
+ width = gr.Slider(label="Ширина", minimum=256, maximum=1024, step=64, value=DEFAULT_IMAGE_SIZE)
89
+ height = gr.Slider(label="Висота", minimum=256, maximum=1024, step=64, value=DEFAULT_IMAGE_SIZE)
90
+ with gr.Row():
91
+ guidance_scale = gr.Slider(label="Guidance Scale", minimum=0, maximum=20, step=0.5, value=7.5)
92
+ num_inference_steps = gr.Slider(label="Кроки інференсу", minimum=10, maximum=100, step=5, value=50)
93
+
94
+ with gr.Row():
95
+ num_images = gr.Slider(label="Кількість зображень", minimum=1, maximum=4, step=1, value=1)
96
 
97
  run_button = gr.Button("Згенерувати")
98
  gallery = gr.Gallery(label="Згенеровані зображення")
 
101
  run_button.click(
102
  fn=generate_image,
103
  inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, num_images, model_choice],
104
+ outputs=[gallery, status_text],
105
  )
106
+
107
+
108
+ demo.launch(share=True)