Update app.py
Browse files
app.py
CHANGED
|
@@ -6,52 +6,45 @@ from PIL import Image
|
|
| 6 |
def process_image(image, filter_intensity, format_choice):
|
| 7 |
# OpenCV๋ก ์ด๋ฏธ์ง ์ฝ๊ธฐ
|
| 8 |
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
| 9 |
-
|
| 10 |
# ํ๋ฐฑ ์ด๋ฏธ์ง ์์ฑ
|
| 11 |
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 12 |
gray_image = cv2.convertScaleAbs(gray_image, alpha=filter_intensity/100)
|
| 13 |
-
|
| 14 |
-
# ์ปฌ๋ฌ ์ด๋ฏธ์ง
|
| 15 |
color_image = cv2.convertScaleAbs(image, alpha=filter_intensity/100)
|
| 16 |
-
|
| 17 |
-
# ์ ํ๋ ํ์์ผ๋ก ์ ์ฅ
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
ext = ".png"
|
| 22 |
-
elif format_choice == "PDF":
|
| 23 |
-
ext = ".pdf"
|
| 24 |
-
else:
|
| 25 |
-
ext = ".jpg"
|
| 26 |
-
|
| 27 |
-
# ์ ์ฅ ํ์ผ ์์ฑ
|
| 28 |
gray_pil = Image.fromarray(gray_image)
|
| 29 |
color_pil = Image.fromarray(cv2.cvtColor(color_image, cv2.COLOR_BGR2RGB))
|
| 30 |
-
|
| 31 |
return gray_pil, color_pil, f"processed_image_gray{ext}", f"processed_image_color{ext}"
|
| 32 |
|
| 33 |
-
# Gradio ์ธํฐํ์ด์ค
|
| 34 |
def app_interface():
|
| 35 |
with gr.Blocks() as app:
|
| 36 |
gr.Markdown("# ์ด๋ฏธ์ง ํํฐ ์ฑ")
|
| 37 |
-
|
| 38 |
with gr.Row():
|
| 39 |
image_input = gr.Image(type="pil", label="์ด๋ฏธ์ง ์
๋ก๋")
|
| 40 |
filter_intensity = gr.Slider(0, 200, value=100, label="ํํฐ ๊ฐ๋ ์กฐ์ ")
|
| 41 |
format_choice = gr.Dropdown(["JPG", "PNG", "PDF"], value="JPG", label="๋ค์ด๋ก๋ ํฌ๋งท ์ ํ")
|
| 42 |
-
|
| 43 |
with gr.Row():
|
| 44 |
gray_output = gr.Image(label="ํ๋ฐฑ ์ด๋ฏธ์ง")
|
| 45 |
color_output = gr.Image(label="์ปฌ๋ฌ ์ด๋ฏธ์ง")
|
| 46 |
-
|
| 47 |
with gr.Row():
|
| 48 |
gray_download = gr.File(label="ํ๋ฐฑ ์ด๋ฏธ์ง ๋ค์ด๋ก๋")
|
| 49 |
color_download = gr.File(label="์ปฌ๋ฌ ์ด๋ฏธ์ง ๋ค์ด๋ก๋")
|
| 50 |
-
|
| 51 |
process_button = gr.Button("์ด๋ฏธ์ง ๋ณํ ๋ฐ ๋ค์ด๋ก๋")
|
| 52 |
process_button.click(process_image,
|
| 53 |
inputs=[image_input, filter_intensity, format_choice],
|
| 54 |
outputs=[gray_output, color_output, gray_download, color_download])
|
|
|
|
| 55 |
return app
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|
|
|
|
| 6 |
def process_image(image, filter_intensity, format_choice):
|
| 7 |
# OpenCV๋ก ์ด๋ฏธ์ง ์ฝ๊ธฐ
|
| 8 |
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
| 9 |
+
|
| 10 |
# ํ๋ฐฑ ์ด๋ฏธ์ง ์์ฑ
|
| 11 |
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 12 |
gray_image = cv2.convertScaleAbs(gray_image, alpha=filter_intensity/100)
|
| 13 |
+
|
| 14 |
+
# ์ปฌ๋ฌ ์ด๋ฏธ์ง ํํฐ ์ ์ฉ
|
| 15 |
color_image = cv2.convertScaleAbs(image, alpha=filter_intensity/100)
|
| 16 |
+
|
| 17 |
+
# ์ ํ๋ ํ์์ผ๋ก ์ ์ฅ ํ์ผ๋ช
์์ฑ
|
| 18 |
+
ext = {"JPG": ".jpg", "PNG": ".png", "PDF": ".pdf"}.get(format_choice, ".jpg")
|
| 19 |
+
|
| 20 |
+
# ๊ฒฐ๊ณผ ์ด๋ฏธ์ง ๋ณํ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
gray_pil = Image.fromarray(gray_image)
|
| 22 |
color_pil = Image.fromarray(cv2.cvtColor(color_image, cv2.COLOR_BGR2RGB))
|
| 23 |
+
|
| 24 |
return gray_pil, color_pil, f"processed_image_gray{ext}", f"processed_image_color{ext}"
|
| 25 |
|
|
|
|
| 26 |
def app_interface():
|
| 27 |
with gr.Blocks() as app:
|
| 28 |
gr.Markdown("# ์ด๋ฏธ์ง ํํฐ ์ฑ")
|
| 29 |
+
|
| 30 |
with gr.Row():
|
| 31 |
image_input = gr.Image(type="pil", label="์ด๋ฏธ์ง ์
๋ก๋")
|
| 32 |
filter_intensity = gr.Slider(0, 200, value=100, label="ํํฐ ๊ฐ๋ ์กฐ์ ")
|
| 33 |
format_choice = gr.Dropdown(["JPG", "PNG", "PDF"], value="JPG", label="๋ค์ด๋ก๋ ํฌ๋งท ์ ํ")
|
| 34 |
+
|
| 35 |
with gr.Row():
|
| 36 |
gray_output = gr.Image(label="ํ๋ฐฑ ์ด๋ฏธ์ง")
|
| 37 |
color_output = gr.Image(label="์ปฌ๋ฌ ์ด๋ฏธ์ง")
|
| 38 |
+
|
| 39 |
with gr.Row():
|
| 40 |
gray_download = gr.File(label="ํ๋ฐฑ ์ด๋ฏธ์ง ๋ค์ด๋ก๋")
|
| 41 |
color_download = gr.File(label="์ปฌ๋ฌ ์ด๋ฏธ์ง ๋ค์ด๋ก๋")
|
| 42 |
+
|
| 43 |
process_button = gr.Button("์ด๋ฏธ์ง ๋ณํ ๋ฐ ๋ค์ด๋ก๋")
|
| 44 |
process_button.click(process_image,
|
| 45 |
inputs=[image_input, filter_intensity, format_choice],
|
| 46 |
outputs=[gray_output, color_output, gray_download, color_download])
|
| 47 |
+
|
| 48 |
return app
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|