Sangwon78 commited on
Commit
8637a9c
Β·
verified Β·
1 Parent(s): d79e44a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -5,7 +5,7 @@ from PIL import Image
5
  import io
6
 
7
  # ν•„ν„° 적용 ν•¨μˆ˜
8
- def apply_filter(image, filter_type, intensity):
9
  image = np.array(image)
10
  if filter_type == "Soft Glow":
11
  blur = cv2.GaussianBlur(image, (15, 15), intensity)
@@ -28,18 +28,19 @@ def apply_filter(image, filter_type, intensity):
28
  image = cv2.cvtColor(gray, cv2.COLOR_GRAY2BGR)
29
  return image
30
 
31
- # Gradio μΈν„°νŽ˜μ΄μŠ€
32
  def process_image(image, filter_type, intensity):
33
  filtered_image = apply_filter(image, filter_type, intensity)
34
  return filtered_image
35
 
36
  def save_image(image, file_format):
 
37
  image = Image.fromarray(image)
38
- buf = io.BytesIO()
39
- image.save(buf, format=file_format)
40
- buf.seek(0)
41
- return buf
42
 
 
43
  with gr.Blocks() as demo:
44
  with gr.Row():
45
  with gr.Column():
@@ -49,7 +50,7 @@ with gr.Blocks() as demo:
49
  value="Soft Glow", label="ν•„ν„° 선택"
50
  )
51
  intensity_slider = gr.Slider(0.1, 2.0, value=1.0, label="ν•„ν„° 강도")
52
- format_dropdown = gr.Dropdown(choices=["JPEG", "PNG", "PDF"], label="μ €μž₯ ν˜•μ‹")
53
  save_button = gr.Button("λ‹€μš΄λ‘œλ“œ")
54
  with gr.Column():
55
  output_image = gr.Image(label="κ²°κ³Ό 이미지", type="numpy")
 
5
  import io
6
 
7
  # ν•„ν„° 적용 ν•¨μˆ˜
8
+ def apply_filter(image, filter_type, intensity):
9
  image = np.array(image)
10
  if filter_type == "Soft Glow":
11
  blur = cv2.GaussianBlur(image, (15, 15), intensity)
 
28
  image = cv2.cvtColor(gray, cv2.COLOR_GRAY2BGR)
29
  return image
30
 
31
+ # Gradio μΈν„°νŽ˜μ΄μŠ€ ν•¨μˆ˜
32
  def process_image(image, filter_type, intensity):
33
  filtered_image = apply_filter(image, filter_type, intensity)
34
  return filtered_image
35
 
36
  def save_image(image, file_format):
37
+ # 이미지λ₯Ό μ €μž₯ν•  μž„μ‹œ 파일 생성
38
  image = Image.fromarray(image)
39
+ temp_file = f"output.{file_format.lower()}"
40
+ image.save(temp_file, format=file_format.upper())
41
+ return temp_file
 
42
 
43
+ # Gradio μΈν„°νŽ˜μ΄μŠ€
44
  with gr.Blocks() as demo:
45
  with gr.Row():
46
  with gr.Column():
 
50
  value="Soft Glow", label="ν•„ν„° 선택"
51
  )
52
  intensity_slider = gr.Slider(0.1, 2.0, value=1.0, label="ν•„ν„° 강도")
53
+ format_dropdown = gr.Dropdown(choices=["JPEG", "PNG"], label="μ €μž₯ ν˜•μ‹")
54
  save_button = gr.Button("λ‹€μš΄λ‘œλ“œ")
55
  with gr.Column():
56
  output_image = gr.Image(label="κ²°κ³Ό 이미지", type="numpy")