Kims12 commited on
Commit
27e15cf
โ€ข
1 Parent(s): 7c01b96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -2,8 +2,12 @@ import gradio as gr
2
  import cv2
3
  import numpy as np
4
  from PIL import Image, ImageEnhance
 
5
 
6
  def apply_filter(image, filter_type, intensity):
 
 
 
7
  # ๊ฐ•๋„๋ฅผ 0.0์—์„œ 1.0 ์‚ฌ์ด๋กœ ์ •๊ทœํ™”
8
  normalized_intensity = intensity / 100.0
9
 
@@ -62,9 +66,7 @@ def convert_to_grayscale(image):
62
 
63
  def convert_and_save(image, filter_type, intensity):
64
  filtered_image = apply_filter(image, filter_type, intensity)
65
- output_path = "output.jpg"
66
- cv2.imwrite(output_path, filtered_image)
67
- return filtered_image, output_path
68
 
69
  def get_filter_description(filter_type):
70
  descriptions = {
@@ -92,10 +94,18 @@ with gr.Blocks() as iface:
92
  description_output = gr.Markdown(get_filter_description("Soft Glow"))
93
 
94
  with gr.Column():
95
- output_image = gr.Image(type="pil", label="๊ฒฐ๊ณผ ์ด๋ฏธ์ง€")
 
 
96
 
97
- filter_input.change(fn=lambda filter_type: get_filter_description(filter_type), inputs=filter_input, outputs=description_output)
98
  process_button = gr.Button("ํ•„ํ„ฐ ์ ์šฉ")
99
- process_button.click(fn=convert_and_save, inputs=[image_input, filter_input, intensity_slider], outputs=output_image)
 
 
 
 
 
 
 
100
 
101
  iface.launch()
 
2
  import cv2
3
  import numpy as np
4
  from PIL import Image, ImageEnhance
5
+ from gradio_imageslider import ImageSlider
6
 
7
  def apply_filter(image, filter_type, intensity):
8
+ # PIL ์ด๋ฏธ์ง€๋ฅผ numpy array๋กœ ๋ณ€ํ™˜
9
+ image = np.array(image)
10
+
11
  # ๊ฐ•๋„๋ฅผ 0.0์—์„œ 1.0 ์‚ฌ์ด๋กœ ์ •๊ทœํ™”
12
  normalized_intensity = intensity / 100.0
13
 
 
66
 
67
  def convert_and_save(image, filter_type, intensity):
68
  filtered_image = apply_filter(image, filter_type, intensity)
69
+ return Image.fromarray(image), Image.fromarray(filtered_image) # ์›๋ณธ๊ณผ ํ•„ํ„ฐ ์ ์šฉ๋œ ์ด๋ฏธ์ง€๋ฅผ ๋ฐ˜ํ™˜
 
 
70
 
71
  def get_filter_description(filter_type):
72
  descriptions = {
 
94
  description_output = gr.Markdown(get_filter_description("Soft Glow"))
95
 
96
  with gr.Column():
97
+ slider_output = ImageSlider(label="Before and After", type="pil")
98
+
99
+ filter_input.change(fn=get_filter_description, inputs=filter_input, outputs=description_output)
100
 
 
101
  process_button = gr.Button("ํ•„ํ„ฐ ์ ์šฉ")
102
+ process_button.click(
103
+ fn=convert_and_save,
104
+ inputs=[image_input, filter_input, intensity_slider],
105
+ outputs=slider_output
106
+ )
107
+
108
+ iface.title = "์ธ๋ฌผ ์‚ฌ์ง„์— ์ตœ์ ํ™”๋œ ํ•„ํ„ฐ"
109
+ iface.description = "์ธ๋ฌผ ์‚ฌ์ง„์— ์ตœ์ ํ™”๋œ ๋‹ค์–‘ํ•œ ํ•„ํ„ฐ๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
110
 
111
  iface.launch()