1_1_mono_img-3 / app.py
vitamom's picture
Update app.py
ccee924 verified
import gradio as gr
import cv2
import numpy as np
from gradio_imageslider import ImageSlider
def convert_to_grayscale(image):
# ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
return gray_image
def convert_and_save(image):
# ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
gray_image = convert_to_grayscale(image)
# ๋ณ€ํ™˜๋œ ์ด๋ฏธ์ง€๋ฅผ JPG๋กœ ์ €์žฅ
output_path = "output.jpg"
cv2.imwrite(output_path, gray_image)
# ์Šฌ๋ผ์ด๋“œ ์ถœ๋ ฅ์šฉ ๋ฆฌ์ŠคํŠธ [์›๋ณธ์ด๋ฏธ์ง€, ํ‘๋ฐฑ์ด๋ฏธ์ง€] ์™€ ์ €์žฅ๋œ ํŒŒ์ผ ๊ฒฝ๋กœ ๋ฐ˜ํ™˜
return [image, gray_image], output_path
# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
iface = gr.Interface(
fn=convert_and_save,
inputs="image",
outputs=[ImageSlider(label="๋ณ€๊ฒฝ ์ „ํ›„ ๋ณด๊ธฐ"), "file"],
title="์ด๋ฏธ์ง€ ํ‘๋ฐฑ ๋ณ€ํ™˜๊ธฐ",
description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๋ฉด ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ , ๊ฒฐ๊ณผ ์ด๋ฏธ์ง€๋ฅผ ์Šฌ๋ผ์ด๋“œ๋กœ ๋น„๊ตํ•ด๋ณผ ์ˆ˜ ์žˆ์œผ๋ฉฐ, JPG ํŒŒ์ผ๋„ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
)
if __name__ == "__main__":
iface.launch()