Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
| 38 |
else:
|
| 39 |
-
|
| 40 |
-
image.save(
|
| 41 |
-
|
|
|
|
| 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="์๋ณธ ์ด๋ฏธ์ง ์
๋ก๋")
|