Reeve's picture
Update app.py
cb50bbd
raw
history blame
1.61 kB
import os
from PIL import Image
from imageio import imwrite
import gradio as gr
from torchvision import transforms
import easydict
import torch
import numpy as np
import cv2
from subprocess import call
def run_cmd(command):
try:
print(command)
call(command, shell=True)
except KeyboardInterrupt:
print("Process interrupted")
sys.exit(1)
run_cmd("pip install basicsr")
run_cmd("pip freeze")
from basicsr.archs.rrdbnet_arch import RRDBNet
from realesrgan import RealESRGANer
from realesrgan.archs.srvgg_arch import SRVGGNetCompact
import train
esrgan_model = train.build_esrgan()
pix2pix_model = train.build_pix2pix()
def pipeline(img, vivid):
img = train.image_preprosses(img, vivid)
if type(img) is np.ndarray:
img, _ = esrgan_model.enhance(img, outscale=4)
img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
img = train.test_pix2pix(img, pix2pix_model)
imwrite('filename.png', img)
return 'filename.png'
description = "์• ๋‹ˆ๋ฉ”์ด์…˜ํ’ ์ด๋ฏธ์ง€๋ฅผ ๋ณผ์งค์ฝ˜ ์Šคํƒ€์ผ๋กœ ๋ฐ”๊พธ๋Š” Pix2pixHD๋ชจ๋ธ์ž…๋‹ˆ๋‹ค. ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ํ›„ ๋‚˜์˜ค๋Š” ์šฐ์ธก ์ƒ๋‹จ์— ์—ฐํ•„๋ชจ์–‘ ํด๋ฆญํ•ด์„œ ์–ผ๊ตด ์ชฝ์„ ์ •์‚ฌ๊ฐํ˜•์œผ๋กœ ์ž๋ฅด๊ณ  submit ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ถœ๋ ฅ ์ด๋ฏธ์ง€๊ฐ€ ํ๋ฆฌ๊ฒŒ ๋‚˜์˜ค๋ฉด ํ™”์งˆ๊ฐœ์„  ์ฒดํฌํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค."
examples=[['siroko_out.png',False]]
gr.Interface(pipeline, [gr.inputs.Image(type="pil"),gr.inputs.Checkbox(default=False, label="ํ™”์งˆ ๊ฐœ์„ ")], gr.outputs.Image(type="file"),description=description,allow_flagging=False,examples=examples,allow_screenshot=False,enable_queue=False).launch()