ssboost commited on
Commit
4e64922
ยท
verified ยท
1 Parent(s): 96bf178

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -48
app.py CHANGED
@@ -146,21 +146,57 @@ def upscale_image(
146
  if os.path.exists(temp_input_path):
147
  os.remove(temp_input_path)
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  def create_interface():
150
  with gr.Blocks(title="Clarity Upscaler") as demo:
151
  with gr.Row():
152
  with gr.Column():
153
  password_input = gr.Textbox(
154
- label="๋น„๋ฐ€๋ฒˆํ˜ธ",
155
- type="password",
156
- placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”"
157
  )
158
  input_image = gr.Image(label="์›๋ณธ ์ด๋ฏธ์ง€", type="pil")
159
 
160
  with gr.Accordion("๊ณ ๊ธ‰ ์„ค์ •", open=False):
161
- scale_factor = gr.Slider(1, 4, value=2, step=0.5, label="ํ™•๋Œ€ ๋น„์œจ")
162
- output_format = gr.Radio(["jpg", "png"], value="jpg", label="์ถœ๋ ฅ ํ˜•์‹")
163
- sd_model = gr.Dropdown(
164
  choices=[
165
  "juggernaut_reborn.safetensors [338b85bc4f]",
166
  "sd_xl_base_1.0.safetensors [39d4e625d]",
@@ -170,57 +206,27 @@ def create_interface():
170
  value="juggernaut_reborn.safetensors [338b85bc4f]",
171
  label="SD ๋ชจ๋ธ"
172
  )
173
- resemblance = gr.Slider(0.0, 1.0, value=0.6, step=0.05, label="์›๋ณธ ์œ ์‚ฌ๋„")
174
- creativity = gr.Slider(0.0, 1.0, value=0.35, step=0.05, label="์ฐฝ์˜์„ฑ")
175
- dynamic = gr.Slider(1, 10, value=6, step=1, label="๋‹ค์ด๋‚˜๋ฏน ์ž„๊ณ„๊ฐ’")
176
- sharpen = gr.Slider(0, 2, value=0, step=0.1, label="์„ ๋ช…๋„")
177
  seed = gr.Number(value=1337, label="์‹œ๋“œ", precision=0)
178
-
179
- submit_btn = gr.Button("์‹คํ–‰", variant="primary")
180
 
181
  with gr.Column():
182
  output_image = gr.Image(label="๊ฐœ์„ ๋œ ์ด๋ฏธ์ง€")
183
- download_btn = gr.DownloadButton(
184
- label="๋‹ค์šด๋กœ๋“œ",
185
- file_name="upscaled.jpg",
186
- mime="image/jpeg"
187
- )
188
 
189
- def process_image(
190
- password, image, scale_factor, output_format, sd_model,
191
- resemblance, creativity, dynamic, sharpen, seed
192
- ):
193
- if password != "1089":
194
- raise ValueError("์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค.")
195
- if image is None:
196
- return None
197
-
198
- return upscale_image(
199
- image=image,
200
- scale_factor=scale_factor,
201
- output_format=output_format,
202
- sd_model=sd_model,
203
- resemblance=resemblance,
204
- creativity=creativity,
205
- dynamic=dynamic,
206
- sharpen=sharpen,
207
- seed=int(seed)
208
- )
209
-
210
- # 1) ์‹คํ–‰ ๋ฒ„ํŠผ โ†’ output_image
211
  submit_btn.click(
212
- fn=process_image,
213
  inputs=[
214
- password_input, input_image, scale_factor, output_format, sd_model,
 
215
  resemblance, creativity, dynamic, sharpen, seed
216
  ],
217
- outputs=[output_image]
218
- )
219
- # 2) ๋‹ค์šด๋กœ๋“œ ๋ฒ„ํŠผ โ†’ output_image ๊ทธ๋Œ€๋กœ ๋ฐ›์•„์„œ ํŒŒ์ผ๋กœ ์ œ๊ณต
220
- download_btn.click(
221
- fn=lambda img: img,
222
- inputs=[output_image],
223
- outputs=[download_btn]
224
  )
225
 
226
  return demo
 
146
  if os.path.exists(temp_input_path):
147
  os.remove(temp_input_path)
148
 
149
+ def process_and_download(
150
+ password, image, scale_factor, output_format, sd_model,
151
+ resemblance, creativity, dynamic, sharpen, seed
152
+ ):
153
+ # 1) ๋น„๋ฐ€๋ฒˆํ˜ธ ๊ฒ€์ฆ
154
+ if password != "1089":
155
+ raise ValueError("์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค.")
156
+ if image is None:
157
+ return None, None
158
+
159
+ # 2) ์ด๋ฏธ์ง€ ์—…์Šค์ผ€์ผ
160
+ result_img = upscale_image(
161
+ image=image,
162
+ scale_factor=scale_factor,
163
+ output_format=output_format,
164
+ sd_model=sd_model,
165
+ resemblance=resemblance,
166
+ creativity=creativity,
167
+ dynamic=dynamic,
168
+ sharpen=sharpen,
169
+ seed=int(seed)
170
+ )
171
+ if result_img is None:
172
+ return None, None
173
+
174
+ # 3) ํŒŒ์ผ๋กœ ์ €์žฅ
175
+ ext = "jpg" if output_format.lower() == "jpg" else "png"
176
+ # JPG๋กœ ์ €์žฅํ•  ๋• RGB ๋ชจ๋“œ๋กœ ๋ณ€ํ™˜
177
+ if ext == "jpg" and result_img.mode == "RGBA":
178
+ result_img = result_img.convert("RGB")
179
+
180
+ filename = f"upscaled_{uuid.uuid4()}.{ext}"
181
+ filepath = os.path.join(TEMP_DIR, filename)
182
+ result_img.save(filepath, format="JPEG" if ext=="jpg" else "PNG")
183
+
184
+ # 4) ๋ฆฌํ„ด: (์ด๋ฏธ์ง€, ํŒŒ์ผ ๊ฒฝ๋กœ)
185
+ return result_img, filepath
186
+
187
  def create_interface():
188
  with gr.Blocks(title="Clarity Upscaler") as demo:
189
  with gr.Row():
190
  with gr.Column():
191
  password_input = gr.Textbox(
192
+ label="๋น„๋ฐ€๋ฒˆํ˜ธ", type="password", placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”"
 
 
193
  )
194
  input_image = gr.Image(label="์›๋ณธ ์ด๋ฏธ์ง€", type="pil")
195
 
196
  with gr.Accordion("๊ณ ๊ธ‰ ์„ค์ •", open=False):
197
+ scale_factor = gr.Slider(1, 4, value=2, step=0.5, label="ํ™•๋Œ€ ๋น„์œจ")
198
+ output_format = gr.Radio(["jpg","png"], value="jpg", label="์ถœ๋ ฅ ํ˜•์‹")
199
+ sd_model = gr.Dropdown(
200
  choices=[
201
  "juggernaut_reborn.safetensors [338b85bc4f]",
202
  "sd_xl_base_1.0.safetensors [39d4e625d]",
 
206
  value="juggernaut_reborn.safetensors [338b85bc4f]",
207
  label="SD ๋ชจ๋ธ"
208
  )
209
+ resemblance = gr.Slider(0.0,1.0, value=0.6, step=0.05, label="์›๋ณธ ์œ ์‚ฌ๋„")
210
+ creativity = gr.Slider(0.0,1.0, value=0.35,step=0.05, label="์ฐฝ์˜์„ฑ")
211
+ dynamic = gr.Slider(1,10, value=6, step=1, label="๋‹ค์ด๋‚˜๋ฏน ์ž„๊ณ„๊ฐ’")
212
+ sharpen = gr.Slider(0,2, value=0, step=0.1, label="์„ ๋ช…๋„")
213
  seed = gr.Number(value=1337, label="์‹œ๋“œ", precision=0)
214
+
215
+ submit_btn = gr.Button("์‹คํ–‰", variant="primary")
216
 
217
  with gr.Column():
218
  output_image = gr.Image(label="๊ฐœ์„ ๋œ ์ด๋ฏธ์ง€")
219
+ download_btn = gr.DownloadButton(label="์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ")
 
 
 
 
220
 
221
+ # ํด๋ฆญ ์‹œ ๋‘ ๊ฐœ์˜ ์ถœ๋ ฅ(์ด๋ฏธ์ง€, ํŒŒ์ผ ๊ฒฝ๋กœ)์„ ๋ฐ˜ํ™˜
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  submit_btn.click(
223
+ fn=process_and_download,
224
  inputs=[
225
+ password_input,
226
+ input_image, scale_factor, output_format, sd_model,
227
  resemblance, creativity, dynamic, sharpen, seed
228
  ],
229
+ outputs=[output_image, download_btn]
 
 
 
 
 
 
230
  )
231
 
232
  return demo