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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -41
app.py CHANGED
@@ -146,18 +146,19 @@ def upscale_image(
146
  if os.path.exists(temp_input_path):
147
  os.remove(temp_input_path)
148
 
149
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
150
  def create_interface():
151
- with gr.Blocks(title="Clarity Upscaler - ์ด๋ฏธ์ง€ ํ™”์งˆ ๊ฐœ์„ ") as demo:
152
- gr.Markdown("# Clarity Upscaler - ์ด๋ฏธ์ง€ ํ™”์งˆ ๊ฐœ์„  ๋„๊ตฌ")
153
- gr.Markdown("Replicate์˜ Clarity Upscaler ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€์˜ ํ™”์งˆ์„ ๊ฐœ์„ ํ•ฉ๋‹ˆ๋‹ค.")
154
-
155
  with gr.Row():
156
  with gr.Column():
 
 
 
 
 
157
  input_image = gr.Image(label="์›๋ณธ ์ด๋ฏธ์ง€", type="pil")
158
-
159
  with gr.Accordion("๊ณ ๊ธ‰ ์„ค์ •", open=False):
160
- scale_factor = gr.Slider(minimum=1, maximum=4, value=2, step=0.5, label="ํ™•๋Œ€ ๋น„์œจ")
161
  output_format = gr.Radio(["jpg", "png"], value="jpg", label="์ถœ๋ ฅ ํ˜•์‹")
162
  sd_model = gr.Dropdown(
163
  choices=[
@@ -169,53 +170,61 @@ def create_interface():
169
  value="juggernaut_reborn.safetensors [338b85bc4f]",
170
  label="SD ๋ชจ๋ธ"
171
  )
172
- resemblance = gr.Slider(minimum=0.0, maximum=1.0, value=0.6, step=0.05, label="์›๋ณธ ์œ ์‚ฌ๋„")
173
- creativity = gr.Slider(minimum=0.0, maximum=1.0, value=0.35, step=0.05, label="์ฐฝ์˜์„ฑ")
174
- dynamic = gr.Slider(minimum=1, maximum=10, value=6, step=1, label="๋‹ค์ด๋‚˜๋ฏน ์ž„๊ณ„๊ฐ’")
175
- sharpen = gr.Slider(minimum=0, maximum=2, value=0, step=0.1, label="์„ ๋ช…๋„")
176
- seed = gr.Number(value=1337, label="์‹œ๋“œ", precision=0)
177
-
178
- submit_btn = gr.Button("ํ™”์งˆ ๊ฐœ์„  ์‹œ์ž‘", variant="primary")
179
 
 
 
180
  with gr.Column():
181
  output_image = gr.Image(label="๊ฐœ์„ ๋œ ์ด๋ฏธ์ง€")
182
-
183
- # ๋กœ๊ทธ ์บก์ฒ˜ ๊ธฐ๋Šฅ ์ œ๊ฑฐ (UI์—์„œ ๋กœ๊ทธ ํ‘œ์‹œํ•˜์ง€ ์•Š์Œ)
184
-
185
- # ์ œ์ถœ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ๋™์ž‘
186
- def process_image(image, scale_factor, output_format, sd_model, resemblance, creativity, dynamic, sharpen, seed):
187
- if image is None:
188
- return None
189
-
190
- try:
191
- result = upscale_image(
192
- image=image,
193
- scale_factor=scale_factor,
194
- output_format=output_format,
195
- sd_model=sd_model,
196
- resemblance=resemblance,
197
- creativity=creativity,
198
- dynamic=dynamic,
199
- sharpen=sharpen,
200
- seed=int(seed)
201
  )
202
- return result
203
- except Exception as e:
204
- logger.error(f"์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}")
 
 
 
 
 
205
  return None
206
-
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  submit_btn.click(
208
- process_image,
209
  inputs=[
210
- input_image, scale_factor, output_format, sd_model,
211
  resemblance, creativity, dynamic, sharpen, seed
212
  ],
213
  outputs=[output_image]
214
  )
215
-
 
 
 
 
 
 
216
  return demo
217
 
218
- # ๋ฉ”์ธ ์‹คํ–‰
219
  if __name__ == "__main__":
220
  demo = create_interface()
221
  demo.launch(share=True)
 
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=[
 
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
227
 
 
228
  if __name__ == "__main__":
229
  demo = create_interface()
230
  demo.launch(share=True)