Sangwon78 commited on
Commit
6a41505
Β·
verified Β·
1 Parent(s): b663262

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
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",