Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
from fpdf import FPDF
|
| 5 |
-
from PIL import Image
|
| 6 |
import io
|
| 7 |
|
| 8 |
|
|
@@ -59,10 +59,14 @@ def save_image(image, output_format):
|
|
| 59 |
# νν° μ μ© λ° λ€μ΄λ‘λ ν¨μ
|
| 60 |
def process_image(image, filter_name, intensity, output_format):
|
| 61 |
try:
|
|
|
|
|
|
|
| 62 |
filtered_image = apply_filter(image, filter_name, intensity)
|
| 63 |
filtered_image_pil = Image.fromarray(cv2.cvtColor(filtered_image, cv2.COLOR_BGR2RGB))
|
| 64 |
file_data, file_name = save_image(filtered_image_pil, output_format)
|
| 65 |
return filtered_image_pil, (file_data, file_name)
|
|
|
|
|
|
|
| 66 |
except Exception as e:
|
| 67 |
raise ValueError(f"μ΄λ―Έμ§ μ²λ¦¬ μ€ μ€λ₯ λ°μ: {str(e)}")
|
| 68 |
|
|
@@ -73,7 +77,7 @@ with gr.Blocks() as demo:
|
|
| 73 |
gr.Markdown("## μ΄λ―Έμ§ νν° λ° λ€μ΄λ‘λ μ ν리μΌμ΄μ
")
|
| 74 |
|
| 75 |
with gr.Row():
|
| 76 |
-
input_image = gr.Image(label="μ΄λ―Έμ§ μ
λ‘λ", type="pil")
|
| 77 |
filter_name = gr.Dropdown(
|
| 78 |
choices=[
|
| 79 |
"Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone",
|
|
|
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
from fpdf import FPDF
|
| 5 |
+
from PIL import Image, UnidentifiedImageError
|
| 6 |
import io
|
| 7 |
|
| 8 |
|
|
|
|
| 59 |
# νν° μ μ© λ° λ€μ΄λ‘λ ν¨μ
|
| 60 |
def process_image(image, filter_name, intensity, output_format):
|
| 61 |
try:
|
| 62 |
+
if image is None:
|
| 63 |
+
raise ValueError("μ΄λ―Έμ§κ° μ
λ‘λλμ§ μμμ΅λλ€.")
|
| 64 |
filtered_image = apply_filter(image, filter_name, intensity)
|
| 65 |
filtered_image_pil = Image.fromarray(cv2.cvtColor(filtered_image, cv2.COLOR_BGR2RGB))
|
| 66 |
file_data, file_name = save_image(filtered_image_pil, output_format)
|
| 67 |
return filtered_image_pil, (file_data, file_name)
|
| 68 |
+
except UnidentifiedImageError:
|
| 69 |
+
raise ValueError("μ¬λ°λ₯΄μ§ μμ μ΄λ―Έμ§ νμμ
λλ€. JPG, PNG νμμ μ΄λ―Έμ§λ₯Ό μ
λ‘λν΄μ£ΌμΈμ.")
|
| 70 |
except Exception as e:
|
| 71 |
raise ValueError(f"μ΄λ―Έμ§ μ²λ¦¬ μ€ μ€λ₯ λ°μ: {str(e)}")
|
| 72 |
|
|
|
|
| 77 |
gr.Markdown("## μ΄λ―Έμ§ νν° λ° λ€μ΄λ‘λ μ ν리μΌμ΄μ
")
|
| 78 |
|
| 79 |
with gr.Row():
|
| 80 |
+
input_image = gr.Image(label="μ΄λ―Έμ§ μ
λ‘λ", type="pil", tool="editor")
|
| 81 |
filter_name = gr.Dropdown(
|
| 82 |
choices=[
|
| 83 |
"Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone",
|