-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
91 lines (71 loc) · 2.21 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import eel
from inpaintGAN.Config import Config
from inpaintGAN.inpaintGAN import InpaintGAN
from PIL import Image, ImageTk
from torchvision.transforms import ToPILImage
import base64
from tkinter import filedialog
import tkinter as tk
import os
import imghdr
modelConfig = {}
folder_path = "none"
eel.init("web", allowed_extensions=['.js', '.html', '.png', '.txt'])
def is_folder_only_images(f_path):
for filename in os.listdir(f_path):
file_path = os.path.join(f_path, filename)
if os.path.isfile(file_path):
if imghdr.what(file_path) is None:
return False
return True
@eel.expose
def train_model():
inpaintConfig = Config()
print(os.path.isdir(folder_path))
inpaintGAN = InpaintGAN(inpaintConfig, modelConfig['dataset_path'])
inpaintGAN.train(eel.setMetrics, eel.addLog)
@eel.expose
def save_model_config(x):
for key in x:
try:
modelConfig[key] = int(x[key])
except:
try:
modelConfig[key] = float(x[key])
except:
modelConfig[key] = x[key]
print(modelConfig)
@eel.expose
def get_dataset_path():
root = tk.Tk()
root.withdraw()
root.attributes('-topmost', True)
folder_path = str(filedialog.askdirectory(parent=root))
eel.writeFolderPath(str(folder_path))
folder_path += "/"
print(os.path.isdir(folder_path))
@eel.expose
def test_model():
inpaintConfig = Config()
inpaintConfig.MASK = 6
inpaintConfig.MODE = 4
inpaintGAN = InpaintGAN(inpaintConfig, "")
inpaintGAN.load()
img = inpaintGAN.fill_image(256)
tensor_to_pil = ToPILImage()
pil_image = tensor_to_pil(img.squeeze())
pil_image.save("web/inference/test.jpeg") # Replace "image.jpg" with the desired file path and extension
@eel.expose
def download_image_file(url):
decoded_data = base64.b64decode(url)
img_file = open('web/inference/image.jpeg', 'wb')
img_file.write(decoded_data)
img_file.close()
@eel.expose
def download_mask_file(url):
decoded_data = base64.b64decode(url)
img_file = open('web/inference/mask.jpeg', 'wb')
img_file.write(decoded_data)
img_file.close()
if __name__ == '__main__':
eel.start("index.html")