Spaces:
Runtime error
Runtime error
File size: 1,377 Bytes
fdc356b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import numpy as np
import cv2
from PIL import Image
from cv2.ximgproc import guidedFilter
import gradio as gr
def clean_image(input_image: Image) -> Image:
img = np.array(input_image).astype(np.float32)
y = img.copy()
for _ in range(64):
y = cv2.bilateralFilter(y, 5, 8, 8)
for _ in range(4):
y = guidedFilter(img, y, 4, 16)
output_image = Image.fromarray(y.clip(0, 255).astype(np.uint8))
return output_image
def example(_image):
pass
def ui():
with gr.Blocks() as app:
with gr.Row():
with gr.Column():
input_image = gr.Image(type="pil", label="Input Image")
start_btn = gr.Button(value="Start", variant="primary")
gr.Examples(
examples=[
["./examples/sample1.jpg"],
["./examples/sample2.jpg"],
["./examples/sample3.jpg"],
],
inputs=[input_image],
outputs=[],
fn=example,
cache_examples=True,
)
with gr.Column():
output_image = gr.Image(type="pil", label="Output Image")
start_btn.click(fn=clean_image, inputs=[input_image], outputs=[output_image])
app.launch()
if __name__ == "__main__":
ui()
|