-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
64 lines (48 loc) · 1.48 KB
/
app.py
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
56
57
58
59
60
from p2p import *
import streamlit as st
from PIL import Image
st.markdown(
"""
<style>
.reportview-container {
background: url("https://i.pinimg.com/originals/aa/dc/21/aadc21a521165193480e7f2b5f22c3d1.jpg")
}
.sidebar .sidebar-content {
background: url("url_goes_here")
}
</style>
""",
unsafe_allow_html=True
)
st.title("C2")
st.subheader("Pix2Pix GAN for Image-to-Image Translation")
@st.cache
def load_image(image_file):
img = Image.open(image_file)
return img
image_file = st.file_uploader("Upload An Image (jpg/jpeg)",type=['png','jpeg','jpg'])
if image_file is not None:
file_details = {"FileName":image_file.name,"FileType":image_file.type}
st.write(file_details)
img = load_image(image_file)
st.image(img, width = 256)
with open(os.path.join("utils/images","image"),"wb") as f:
f.write(image_file.getbuffer())
st.success("Saved File")
gen = torch.load("utils/WEIGHTS/pix2pix.pth", map_location = "cpu")
DEVICE = "cpu"
dir = "utils/images"
val_dataset = AnimuDataset(root_dir=dir)
val_loader = DataLoader(val_dataset, batch_size=1, shuffle=False)
x, y = next(iter(val_loader))
x, y = x.to(DEVICE), y.to(DEVICE)
gen.eval()
epoch = 1
folder = "utils/result"
with torch.no_grad():
y_fake = gen(x)
y_fake = y_fake * 0.5 + 0.5 # remove normalization#
save_image(y_fake, folder + f"/y_gen_{epoch}.png")
st.write("Pixelating...")
result = "utils/result/y_gen_1.png"
st.image(result)