geninhu commited on
Commit
98c3ab4
1 Parent(s): fcae87c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -11
app.py CHANGED
@@ -3,7 +3,7 @@ import numpy as np
3
  import streamlit as st
4
 
5
  from models import Generator, Discriminrator
6
- from utils import image_to_base64
7
  import torch
8
  import torchvision.transforms as T
9
  from torchvision.utils import make_grid
@@ -130,22 +130,16 @@ def main():
130
  unsafe_allow_html=True,
131
  )
132
 
133
- st.header("Welcome to FastGAN")
134
-
135
  if choose == 'Model Gallery':
 
136
  show_model_summary(True)
137
  elif choose == 'Create your own images':
138
- #checked = st.checkbox('Click here if you want to create one of your own !')
139
-
140
- # if not checked:
141
- # show_model_summary(True)
142
- # if checked:
143
- # show_model_summary(False)
144
  col11, col12, col13 = st.columns([3,3.5,3.5])
145
  with col11:
146
  img_type = st.selectbox("Choose type of image to generate", index=0,
147
  options=["aurora", "anime", "painting", "fauvism", "shell", "universe", "grumpy cat", "moon gate"])
148
- # with col12:
149
  number_imgs = st.slider('How many images you want to generate ?', min_value=1, max_value=5)
150
  if number_imgs is None:
151
  st.write('Invalid number ! Please insert number of images to generate !')
@@ -172,8 +166,35 @@ def main():
172
  st.image(gan_images[1], width=300)
173
  else:
174
  st.image(gan_images[1:], width=150)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
 
176
-
 
 
 
 
 
 
 
 
 
177
 
178
  if __name__ == '__main__':
179
  main()
 
3
  import streamlit as st
4
 
5
  from models import Generator, Discriminrator
6
+ from StyleMix import style_mix
7
  import torch
8
  import torchvision.transforms as T
9
  from torchvision.utils import make_grid
 
130
  unsafe_allow_html=True,
131
  )
132
 
 
 
133
  if choose == 'Model Gallery':
134
+ st.header("Welcome to FastGAN")
135
  show_model_summary(True)
136
  elif choose == 'Create your own images':
137
+ st.header("Generate images")
 
 
 
 
 
138
  col11, col12, col13 = st.columns([3,3.5,3.5])
139
  with col11:
140
  img_type = st.selectbox("Choose type of image to generate", index=0,
141
  options=["aurora", "anime", "painting", "fauvism", "shell", "universe", "grumpy cat", "moon gate"])
142
+
143
  number_imgs = st.slider('How many images you want to generate ?', min_value=1, max_value=5)
144
  if number_imgs is None:
145
  st.write('Invalid number ! Please insert number of images to generate !')
 
166
  st.image(gan_images[1], width=300)
167
  else:
168
  st.image(gan_images[1:], width=150)
169
+
170
+ elif choose == 'Style mix':
171
+ st.header("Style mix")
172
+ st.markdown(
173
+ """
174
+ <p style='text-align: left'>
175
+ Get the style representations of 2 images generated from the model to create a new one that mixes the style of two.
176
+ </p>
177
+ """,
178
+ unsafe_allow_html=True,
179
+ )
180
+ st.markdown("""___""")
181
+ col21, col22 = st.columns([3, 6])
182
+ with col21:
183
+ img_type = st.selectbox("Choose type of image to mix", index=0,
184
+ options=["aurora", "anime", "painting", "fauvism", "shell", "universe", "grumpy cat", "moon gate"])
185
+ number_imgs = st.slider('How many images you want to generate ?', min_value=1, max_value=3)
186
+ generate_button = st.button('Mix style')
187
 
188
+ if generate_button:
189
+ with col21:
190
+ with st.spinner(text=f"Mixing styles..."):
191
+ mix_imgs = style_mix(model_name[img_type], number_imgs, device)
192
+ mix_imgs = make_grid(mix_imgs, nrow=number_imgs+1, normalize=True)
193
+ mix_imgs = mix_imgs.mul(255).add_(0.5).clamp_(0, 255).permute(1, 2, 0).to("cpu", torch.uint8).numpy()
194
+ mix_imgs = Image.fromarray(mix_imgs)
195
+ with col22:
196
+ st.image(mix_imgs, width=600)
197
+
198
 
199
  if __name__ == '__main__':
200
  main()