Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transforms2 = A.Compose(
|
2 |
+
[
|
3 |
+
A.Resize(width=256, height=256),
|
4 |
+
A.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5], max_pixel_value=255),
|
5 |
+
ToTensorV2(),
|
6 |
+
],
|
7 |
+
is_check_shapes=False
|
8 |
+
)
|
9 |
+
def style_transfer(img_file):
|
10 |
+
img = np.array(Image.open(img_file))
|
11 |
+
transform_img = transforms2(image=img)
|
12 |
+
input_img = transform_img["image"]
|
13 |
+
input_img = input_img.to(DEVICE)
|
14 |
+
output_img = genA(input_img)
|
15 |
+
return postprocess_and_show(output_img)
|
16 |
+
#save_image(output_img*0.5 + 0.5, f"/kaggle/working/output.png")
|
17 |
+
|
18 |
+
|
19 |
+
image_input = gr.Image(type="filepath")
|
20 |
+
image_output = gr.Image()
|
21 |
+
|
22 |
+
demo = gr.Interface(fn=style_transfer, inputs=image_input, outputs=image_output, title="Style Transfer with CycleGAN")
|
23 |
+
|
24 |
+
if __name__ == "__main__":
|
25 |
+
demo.launch()
|