Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from PIL import Image
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
# νν°
|
| 7 |
def apply_filter(image, filter_type, intensity):
|
| 8 |
img = np.array(image)
|
| 9 |
|
|
@@ -28,35 +28,39 @@ def apply_filter(image, filter_type, intensity):
|
|
| 28 |
|
| 29 |
return Image.fromarray(img)
|
| 30 |
|
| 31 |
-
# νμΌ μ μ₯
|
| 32 |
def save_file(image, format):
|
| 33 |
file_path = f"processed_image.{format.lower()}"
|
| 34 |
image.save(file_path, format=format)
|
| 35 |
return file_path
|
| 36 |
|
| 37 |
-
#
|
| 38 |
def process_image(image, filter_type, intensity, file_format):
|
| 39 |
filtered_image = apply_filter(image, filter_type, intensity)
|
| 40 |
download_path = save_file(filtered_image, file_format)
|
| 41 |
return filtered_image, download_path
|
| 42 |
|
| 43 |
-
# UI ꡬμ±
|
| 44 |
with gr.Blocks() as demo:
|
| 45 |
-
gr.Markdown("# μ΄λ―Έμ§ νν°
|
|
|
|
|
|
|
| 46 |
with gr.Row():
|
| 47 |
-
image_input = gr.Image(type="pil", label="μ΄λ―Έμ§
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
# λμ μ°κ²°
|
| 59 |
-
submit_button = gr.Button("νν° μ μ©")
|
| 60 |
submit_button.click(
|
| 61 |
process_image,
|
| 62 |
inputs=[image_input, filter_selector, intensity_slider, file_format_selector],
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
+
# νν° μ μ© ν¨μ
|
| 7 |
def apply_filter(image, filter_type, intensity):
|
| 8 |
img = np.array(image)
|
| 9 |
|
|
|
|
| 28 |
|
| 29 |
return Image.fromarray(img)
|
| 30 |
|
| 31 |
+
# νμΌ μ μ₯ ν¨μ
|
| 32 |
def save_file(image, format):
|
| 33 |
file_path = f"processed_image.{format.lower()}"
|
| 34 |
image.save(file_path, format=format)
|
| 35 |
return file_path
|
| 36 |
|
| 37 |
+
# μ΄λ―Έμ§ λ³ν ν λ°ν
|
| 38 |
def process_image(image, filter_type, intensity, file_format):
|
| 39 |
filtered_image = apply_filter(image, filter_type, intensity)
|
| 40 |
download_path = save_file(filtered_image, file_format)
|
| 41 |
return filtered_image, download_path
|
| 42 |
|
| 43 |
+
# Gradio UI ꡬμ±
|
| 44 |
with gr.Blocks() as demo:
|
| 45 |
+
gr.Markdown("# π· μ΄λ―Έμ§ νν° λ³νκΈ°")
|
| 46 |
+
gr.Markdown("μ΄λ―Έμ§λ₯Ό μ
λ‘λνκ³ μνλ νν°λ₯Ό ν΄λ¦ν΄ λ³νν΄ λ³΄μΈμ!")
|
| 47 |
+
|
| 48 |
with gr.Row():
|
| 49 |
+
image_input = gr.Image(type="pil", label="μ΄λ―Έμ§ μ ν")
|
| 50 |
+
with gr.Column():
|
| 51 |
+
filter_selector = gr.Dropdown(
|
| 52 |
+
["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone",
|
| 53 |
+
"High-Key", "Low-Key", "Haze", "Monochrome"],
|
| 54 |
+
label="νν° μ ν"
|
| 55 |
+
)
|
| 56 |
+
intensity_slider = gr.Slider(0.0, 1.0, value=0.5, label="νν° κ°λ")
|
| 57 |
+
file_format_selector = gr.Radio(["JPG", "PNG", "PDF"], label="νμΌ νμ")
|
| 58 |
+
submit_button = gr.Button("λ³ν μ μ©")
|
| 59 |
+
|
| 60 |
+
output_image = gr.Image(label="λ³νλ μ΄λ―Έμ§")
|
| 61 |
+
download_button = gr.File(label="λ€μ΄λ‘λ λ§ν¬")
|
| 62 |
|
| 63 |
+
# λ²νΌ ν΄λ¦ μ λμ μ°κ²°
|
|
|
|
| 64 |
submit_button.click(
|
| 65 |
process_image,
|
| 66 |
inputs=[image_input, filter_selector, intensity_slider, file_format_selector],
|