Download app.py from Sangwon78/example1: direct link, hf CLI and curl.
- Browser
- Download file 2.41 kB
-
https://huggingface.co/spaces/Sangwon78/example1/resolve/main/app.py
- Command line
-
hf download hf://spaces/Sangwon78/example1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Sangwon78/example1/resolve/main/app.py
2.41 kB
| import gradio as gr | |
| import cv2 | |
| import numpy as np | |
| from PIL import Image, ImageEnhance | |
| def process_image(image, filter_type, brightness, tone, sensitivity): | |
| # Convert image to OpenCV format | |
| img_array = np.array(image) | |
| if filter_type == "Grayscale": | |
| img_processed = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY) | |
| img_processed = cv2.cvtColor(img_processed, cv2.COLOR_GRAY2RGB) # Convert back to 3-channel | |
| elif filter_type == "Color": | |
| img_processed = img_array # Keep original color | |
| # Adjust tone and sensitivity | |
| img_processed = cv2.convertScaleAbs(img_processed, alpha=tone, beta=sensitivity) | |
| # Convert to PIL for brightness adjustment | |
| img_pil = Image.fromarray(img_processed) | |
| enhancer = ImageEnhance.Brightness(img_pil) | |
| img_brightened = enhancer.enhance(brightness) | |
| return np.array(img_brightened) | |
| def save_image(image, output_format): | |
| output_path = f"output.{output_format.lower()}" | |
| pil_image = Image.fromarray(image) | |
| pil_image.save(output_path) | |
| return output_path | |
| def app_function(image, filter_type, brightness, tone, sensitivity, output_format): | |
| processed_image = process_image(image, filter_type, brightness, tone, sensitivity) | |
| download_path = save_image(processed_image, output_format) | |
| return processed_image, download_path | |
| with gr.Blocks() as demo: | |
| gr.Markdown("### ์ด๋ฏธ์ง ๋ณํ ๋ฐ ๋ค์ด๋ก๋ ํ๋ก๊ทธ๋จ") | |
| with gr.Row(): | |
| with gr.Column(): | |
| image_input = gr.Image(type="pil", label="์ด๋ฏธ์ง ์ ๋ก๋") | |
| filter_type = gr.Radio(["Grayscale", "Color"], label="ํํฐ ์ ํ", value="Grayscale") | |
| brightness = gr.Slider(0.5, 2.0, step=0.1, value=1.0, label="๋ฐ๊ธฐ ์กฐ์ ") | |
| tone = gr.Slider(0.5, 2.0, step=0.1, value=1.0, label="ํค ์กฐ์ ") | |
| sensitivity = gr.Slider(-100, 100, step=10, value=0, label="ํํฐ ๊ฐ๋") | |
| output_format = gr.Radio(["JPG", "PNG", "PDF"], label="์ถ๋ ฅ ํ์ ์ ํ", value="JPG") | |
| with gr.Column(): | |
| output_image = gr.Image(label="๊ฒฐ๊ณผ ์ด๋ฏธ์ง") | |
| download_button = gr.File(label="๋ค์ด๋ก๋") | |
| btn = gr.Button("์ด๋ฏธ์ง ๋ณํ ๋ฐ ์ ์ฅ") | |
| btn.click( | |
| app_function, | |
| inputs=[image_input, filter_type, brightness, tone, sensitivity, output_format], | |
| outputs=[output_image, download_button] | |
| ) | |
| demo.launch() | |