Aanisha commited on
Commit
45455e8
1 Parent(s): 6b8aec5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -1
app.py CHANGED
@@ -103,7 +103,7 @@ class ImageTransform:
103
  transforms.Resize((img_size, img_size)),
104
  transforms.ToTensor(),
105
  transforms.Normalize(mean=[0.5], std=[0.5])
106
- })}
107
 
108
  def __call__(self, img, phase='train'):
109
  img = self.transform[phase](img)
@@ -114,6 +114,44 @@ class ImageTransform:
114
  path = hf_hub_download('huggan/NeonGAN', 'model.bin')
115
  model_gen_n = torch.load(path, map_location=torch.device('cpu'))
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
 
119
 
 
103
  transforms.Resize((img_size, img_size)),
104
  transforms.ToTensor(),
105
  transforms.Normalize(mean=[0.5], std=[0.5])
106
+ ])}
107
 
108
  def __call__(self, img, phase='train'):
109
  img = self.transform[phase](img)
 
114
  path = hf_hub_download('huggan/NeonGAN', 'model.bin')
115
  model_gen_n = torch.load(path, map_location=torch.device('cpu'))
116
 
117
+ transform = ImageTransform(img_size=256)
118
+
119
+ inputs = [
120
+ gr.inputs.Image(type="pil", label="Original Image")
121
+ ]
122
+
123
+ outputs = [
124
+ gr.outputs.Image(type="pil", label="Neon Image")
125
+ ]
126
+
127
+ def get_output_image(img):
128
+
129
+ img = transform(img, phase='test')
130
+ gen_img = model_gen_n(img.unsqueeze(0))[0]
131
+
132
+ # Reverse Normalization
133
+ gen_img = gen_img * 0.5 + 0.5
134
+ gen_img = gen_img * 255
135
+ gen_img = gen_img.detach().cpu().numpy().astype(np.uint8)
136
+
137
+ gen_img = np.transpose(gen_img, [1,2,0])
138
+
139
+ gen_img = Image.fromarray(gen_img)
140
+
141
+ return gen_img
142
+
143
+ gr.Interface(
144
+ get_output_image,
145
+ inputs,
146
+ outputs,
147
+ examples = examples,
148
+ title=title,
149
+ description=description,
150
+ theme="huggingface",
151
+ ).launch(enable_queue=True)
152
+
153
+
154
+
155
 
156
 
157