Download app.py from Sangwon78/SEO: direct link, hf CLI and curl.
- Browser
- Download file 2.39 kB
-
https://huggingface.co/spaces/Sangwon78/SEO/resolve/main/app.py
- Command line
-
hf download hf://spaces/Sangwon78/SEO/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Sangwon78/SEO/resolve/main/app.py
2.39 kB
| import gradio as gr | |
| import cv2 | |
| import numpy as np | |
| def convert_to_grayscale(image): | |
| # ์ด๋ฏธ์ง๋ฅผ ํ๋ฐฑ์ผ๋ก ๋ณํ | |
| gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
| return gray_image | |
| def apply_filter(image, filter_type): | |
| if filter_type == "Soft Glow": | |
| # ๋ถ๋๋ฌ์ด ๋น ํจ๊ณผ | |
| blurred = cv2.GaussianBlur(image, (15, 15), 0) | |
| soft_glow = cv2.addWeighted(image, 0.5, blurred, 0.5, 0) | |
| return soft_glow | |
| elif filter_type == "Portrait Enhancer": | |
| # ์ด์ํ ๊ฐํ ํจ๊ณผ | |
| kernel = np.array([[0, -1, 0], [-1, 5,-1], [0, -1, 0]]) | |
| enhanced = cv2.filter2D(image, -1, kernel) | |
| return enhanced | |
| elif filter_type == "Warm Tone": | |
| # ๋ฐ๋ปํ ํค ํจ๊ณผ | |
| warm = cv2.applyColorMap(image, cv2.COLORMAP_AUTUMN) | |
| return warm | |
| elif filter_type == "Cold Tone": | |
| # ์ฐจ๊ฐ์ด ํค ํจ๊ณผ | |
| cold = cv2.applyColorMap(image, cv2.COLORMAP_WINTER) | |
| return cold | |
| elif filter_type == "High-Key": | |
| # ํ์ดํค ํจ๊ณผ | |
| high_key = cv2.convertScaleAbs(image, alpha=1.2, beta=50) | |
| return high_key | |
| elif filter_type == "Low-Key": | |
| # ๋ก์ฐํค ํจ๊ณผ | |
| low_key = cv2.convertScaleAbs(image, alpha=0.8, beta=-30) | |
| return low_key | |
| elif filter_type == "Haze": | |
| # ํค์ด์ฆ ํจ๊ณผ | |
| haze = cv2.addWeighted(image, 0.8, np.full(image.shape, 255, dtype=np.uint8), 0.2, 0) | |
| return haze | |
| else: | |
| # ํํฐ๊ฐ ์ ํ๋์ง ์์์ ๊ฒฝ์ฐ ์๋ณธ ๋ฐํ | |
| return image | |
| def convert_and_save_with_filter(image, filter_type): | |
| # ์ ํํ ํํฐ ์ ์ฉ ๋ฐ ํ๋ฐฑ ๋ณํ | |
| filtered_image = apply_filter(image, filter_type) | |
| gray_image = convert_to_grayscale(filtered_image) | |
| output_path = "output.jpg" | |
| cv2.imwrite(output_path, gray_image) | |
| return gray_image, output_path | |
| # Gradio ์ธํฐํ์ด์ค ์ ์ | |
| iface = gr.Interface( | |
| fn=convert_and_save_with_filter, | |
| inputs=["image", gr.Radio(["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], label="Select Filter")], | |
| outputs=["image", "file"], | |
| title="์ด๋ฏธ์ง ํ๋ฐฑ ๋ณํ๊ธฐ ๋ฐ ํํฐ ์ ์ฉ", | |
| description="์ด๋ฏธ์ง๋ฅผ ์ ๋ก๋ํ๊ณ ํํฐ๋ฅผ ์ ํํ๋ฉด ํ๋ฐฑ์ผ๋ก ๋ณํํ๊ณ JPG ํ์ผ๋ก ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |