Sangwon78 commited on
Commit
cdc423d
ยท
verified ยท
1 Parent(s): 507145e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -3,6 +3,7 @@ import cv2
3
  import numpy as np
4
  from fpdf import FPDF
5
  from PIL import Image
 
6
 
7
  # ํ•„ํ„ฐ ํ•จ์ˆ˜ ์ •์˜
8
  def apply_filter(image, filter_name, intensity):
@@ -34,22 +35,25 @@ def save_image(image, format):
34
  temp_image = "temp.jpg"
35
  image.save(temp_image)
36
  pdf.image(temp_image, x=10, y=10, w=180)
37
- return pdf.output(dest='S').encode('latin1')
 
 
38
  else:
39
- image_bytes = io.BytesIO()
40
- image.save(image_bytes, format=format)
41
- return image_bytes.getvalue()
 
42
 
43
  # Gradio ์•ฑ ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
44
  def process_image(image, filter_name, intensity, output_format):
45
  filtered_image = apply_filter(image, filter_name, intensity)
46
  filtered_image_pil = Image.fromarray(cv2.cvtColor(filtered_image, cv2.COLOR_BGR2RGB))
47
  download_file = save_image(filtered_image_pil, output_format)
48
- return filtered_image_pil, download_file
49
 
50
  with gr.Blocks() as demo:
51
  with gr.Row():
52
- gr.Markdown("## ์ด๋ฏธ์ง€ ํ•„ํ„ฐ ๋ณ€ํ™˜ ์•ฑ")
53
 
54
  with gr.Row():
55
  input_image = gr.Image(label="์›๋ณธ ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ")
 
3
  import numpy as np
4
  from fpdf import FPDF
5
  from PIL import Image
6
+ import io
7
 
8
  # ํ•„ํ„ฐ ํ•จ์ˆ˜ ์ •์˜
9
  def apply_filter(image, filter_name, intensity):
 
35
  temp_image = "temp.jpg"
36
  image.save(temp_image)
37
  pdf.image(temp_image, x=10, y=10, w=180)
38
+ output = io.BytesIO()
39
+ pdf.output(dest='S').encode('latin1')
40
+ return output.getvalue()
41
  else:
42
+ output = io.BytesIO()
43
+ image.save(output, format=format)
44
+ output.seek(0)
45
+ return output
46
 
47
  # Gradio ์•ฑ ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
48
  def process_image(image, filter_name, intensity, output_format):
49
  filtered_image = apply_filter(image, filter_name, intensity)
50
  filtered_image_pil = Image.fromarray(cv2.cvtColor(filtered_image, cv2.COLOR_BGR2RGB))
51
  download_file = save_image(filtered_image_pil, output_format)
52
+ return filtered_image_pil, (download_file, f"output.{output_format.lower()}")
53
 
54
  with gr.Blocks() as demo:
55
  with gr.Row():
56
+ gr.Markdown("## ์ด๋ฏธ์ง€ ํ•„ํ„ฐ ๋ณ€ํ™˜ ๋ฐ ๋‹ค์šด๋กœ๋“œ ์•ฑ")
57
 
58
  with gr.Row():
59
  input_image = gr.Image(label="์›๋ณธ ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ")