Download app.py from Sangwon78/Example2: direct link, hf CLI and curl.
- Browser
- Download file 2.51 kB
-
https://huggingface.co/spaces/Sangwon78/Example2/resolve/d79e44a5ea25b4df7977d71b9a246d397f97aec6/app.py
- Command line
-
hf download hf://spaces/Sangwon78/Example2@d79e44a5ea25b4df7977d71b9a246d397f97aec6/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Sangwon78/Example2/resolve/d79e44a5ea25b4df7977d71b9a246d397f97aec6/app.py
2.51 kB
| import gradio as gr | |
| import cv2 | |
| import numpy as np | |
| from PIL import Image | |
| import io | |
| # ํํฐ ์ ์ฉ ํจ์ | |
| def apply_filter(image, filter_type, intensity): | |
| image = np.array(image) | |
| if filter_type == "Soft Glow": | |
| blur = cv2.GaussianBlur(image, (15, 15), intensity) | |
| image = cv2.addWeighted(image, 1.0, blur, 0.5, 0) | |
| elif filter_type == "Portrait Enhancer": | |
| image = cv2.detailEnhance(image, sigma_s=10, sigma_r=0.15 * intensity) | |
| elif filter_type == "Warm Tone": | |
| image = cv2.transform(image, np.array([[[1.1, 0.95, 0.8]]]) * intensity) | |
| elif filter_type == "Cold Tone": | |
| image = cv2.transform(image, np.array([[[0.9, 1.1, 1.2]]]) * intensity) | |
| elif filter_type == "High-Key": | |
| image = cv2.add(image, np.array([intensity * 50.0])) | |
| elif filter_type == "Low-Key": | |
| image = cv2.add(image, np.array([-intensity * 50.0])) | |
| elif filter_type == "Haze": | |
| haze = cv2.GaussianBlur(image, (int(5 * intensity), int(5 * intensity)), 0) | |
| image = cv2.addWeighted(image, 0.5, haze, 0.5, 0) | |
| elif filter_type == "Monochrome": | |
| gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
| image = cv2.cvtColor(gray, cv2.COLOR_GRAY2BGR) | |
| return image | |
| # Gradio ์ธํฐํ์ด์ค | |
| def process_image(image, filter_type, intensity): | |
| filtered_image = apply_filter(image, filter_type, intensity) | |
| return filtered_image | |
| def save_image(image, file_format): | |
| image = Image.fromarray(image) | |
| buf = io.BytesIO() | |
| image.save(buf, format=file_format) | |
| buf.seek(0) | |
| return buf | |
| with gr.Blocks() as demo: | |
| with gr.Row(): | |
| with gr.Column(): | |
| input_image = gr.Image(label="์ ๋ก๋ ์ด๋ฏธ์ง", type="numpy") | |
| filter_choice = gr.Dropdown( | |
| choices=["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze", "Monochrome"], | |
| value="Soft Glow", label="ํํฐ ์ ํ" | |
| ) | |
| intensity_slider = gr.Slider(0.1, 2.0, value=1.0, label="ํํฐ ๊ฐ๋") | |
| format_dropdown = gr.Dropdown(choices=["JPEG", "PNG", "PDF"], label="์ ์ฅ ํ์") | |
| save_button = gr.Button("๋ค์ด๋ก๋") | |
| with gr.Column(): | |
| output_image = gr.Image(label="๊ฒฐ๊ณผ ์ด๋ฏธ์ง", type="numpy") | |
| input_image.change(process_image, [input_image, filter_choice, intensity_slider], output_image) | |
| save_button.click(save_image, [output_image, format_dropdown], outputs=gr.File(label="ํ์ผ ์ ์ฅ")) | |
| demo.launch() | |