Update app.py
Browse files
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
|
162 |
-
output_format = gr.Radio(["jpg",
|
163 |
-
sd_model
|
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,
|
174 |
-
creativity = gr.Slider(0.0,
|
175 |
-
dynamic = gr.Slider(1,
|
176 |
-
sharpen = gr.Slider(0,
|
177 |
seed = gr.Number(value=1337, label="์๋", precision=0)
|
178 |
-
|
179 |
-
submit_btn
|
180 |
|
181 |
with gr.Column():
|
182 |
output_image = gr.Image(label="๊ฐ์ ๋ ์ด๋ฏธ์ง")
|
183 |
-
download_btn
|
184 |
-
label="๋ค์ด๋ก๋",
|
185 |
-
file_name="upscaled.jpg",
|
186 |
-
mime="image/jpeg"
|
187 |
-
)
|
188 |
|
189 |
-
|
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=
|
213 |
inputs=[
|
214 |
-
password_input,
|
|
|
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
|