EmoCube commited on
Commit
3079d5a
·
verified ·
1 Parent(s): bef47e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -74,6 +74,22 @@ def resize_and_crop(image, target_width=768, target_height=1024):
74
  cropped_image = resized_image.crop((left, top, right, bottom))
75
  return cropped_image
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  def query(prompt):
78
  if prompt == "" or prompt == None:
79
  return None
@@ -101,6 +117,7 @@ def query(prompt):
101
 
102
  image = add_noise(image, intensity=12.5)
103
  image = resize_and_crop(image, 360, 640)
 
104
 
105
  # Изменение насыщенности
106
  enhancer = ImageEnhance.Color(image)
@@ -127,13 +144,23 @@ css = """
127
  }
128
  """
129
 
 
 
 
 
 
 
 
 
 
 
130
  with gr.Blocks(theme='gstaff/xkcd', css=css) as app:
131
  gr.HTML("<center><h1>FLUX.1-Schnell</h1></center>")
132
  with gr.Column(elem_id="app-container"):
133
  with gr.Row():
134
  with gr.Column(elem_id="prompt-container"):
135
  with gr.Row():
136
- text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2, elem_id="prompt-text-input")
137
 
138
  with gr.Row():
139
  text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
 
74
  cropped_image = resized_image.crop((left, top, right, bottom))
75
  return cropped_image
76
 
77
+ def compress_image(image, quality=50):
78
+ """
79
+ Сжимает изображение и понижает его качество в формате JPEG.
80
+ :param image: Изображение (PIL.Image)
81
+ :param quality: Качество JPEG (от 1 до 100)
82
+ :return: Сжатое изображение (PIL.Image)
83
+ """
84
+ # Сохраняем изображение в буфер с пониженным качеством
85
+ buffer = io.BytesIO()
86
+ image.save(buffer, format="JPEG", quality=quality)
87
+ buffer.seek(0)
88
+
89
+ # Загружаем изображение обратно из буфера
90
+ compressed_image = Image.open(buffer)
91
+ return compressed_image
92
+
93
  def query(prompt):
94
  if prompt == "" or prompt == None:
95
  return None
 
117
 
118
  image = add_noise(image, intensity=12.5)
119
  image = resize_and_crop(image, 360, 640)
120
+ image = compress_image(image, 75)
121
 
122
  # Изменение насыщенности
123
  enhancer = ImageEnhance.Color(image)
 
144
  }
145
  """
146
 
147
+ test_prompt = """(
148
+ [russian athletic female with brown eyes and gold loose long hair (her clothes: with gray cotton sweater, with pink mini-skirt, with black cotton short socks, with beige sandals. Clothes and female may no visible or hidden), smiling and laying on something]
149
+ [realistic photo with poor pale lighting]
150
+ [detailed living room composition (may be people)]
151
+ [morning light, pale tones]
152
+ [home russian atmosphere]
153
+ [no mutation glitches, natural anatomy]
154
+ [amateur one hand-selfie pov side angle]
155
+ )"""
156
+
157
  with gr.Blocks(theme='gstaff/xkcd', css=css) as app:
158
  gr.HTML("<center><h1>FLUX.1-Schnell</h1></center>")
159
  with gr.Column(elem_id="app-container"):
160
  with gr.Row():
161
  with gr.Column(elem_id="prompt-container"):
162
  with gr.Row():
163
+ text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2, elem_id="prompt-text-input", value=test_prompt)
164
 
165
  with gr.Row():
166
  text_button = gr.Button("Run", variant='primary', elem_id="gen-button")