Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import numpy as np
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 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 |
+
if format_choice == "JPG":
|
| 19 |
+
ext = ".jpg"
|
| 20 |
+
elif format_choice == "PNG":
|
| 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__":
|
| 58 |
+
app = app_interface()
|
| 59 |
+
app.launch()
|