Hugomartinezg commited on
Commit
b6d8fe5
verified
1 Parent(s): 387d148

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -43
app.py CHANGED
@@ -1,59 +1,45 @@
1
  import streamlit as st
 
2
 
3
- from utils import carga_modelo, genera
4
 
5
- ## P谩gina principal
6
- st.title("Butterfly GAN (GAN de mariposas)")
7
- st.write(
8
- "Modelo Light-GAN entrenado con 1000 im谩genes de mariposas tomadas de la colecci贸n del Museo Smithsonian."
9
- )
10
 
11
- ## Barra lateral
12
- st.sidebar.subheader("隆Esta mariposa no existe! Ni en Am茅rica Latina 馃く.")
13
- ## st.sidebar.image("logo.png", width=200)
14
- st.sidebar.caption(
15
- f"[Modelo](https://huggingface.co/ceyda/butterfly_cropped_uniq1K_512) y [Dataset](https://huggingface.co/datasets/huggan/smithsonian_butterflies_subset) usados."
16
- )
17
- st.sidebar.caption(f"*Disclaimers:*")
18
- st.sidebar.caption(
19
- "* Este demo es una versi贸n simplificada del creado por [Ceyda Cinarel](https://github.com/cceyda) y [Jonathan Whitaker](https://datasciencecastnet.home.blog/) ([link](https://huggingface.co/spaces/huggan/butterfly-gan)) durante el hackathon [HugGan](https://github.com/huggingface/community-events)."
20
- )
21
- st.sidebar.caption(
22
- "* Modelo basado en el [paper](https://openreview.net/forum?id=1Fqg133qRaI) *Towards Faster and Stabilized GAN Training for High-fidelity Few-shot Image Synthesis*."
23
- )
24
 
25
- ## Cargamos modelo
26
- repo_id = "ceyda/butterfly_cropped_uniq1K_512"
27
- version_modelo = "57d36a15546909557d9f967f47713236c8288838"
28
- modelo_gan = carga_modelo(repo_id, version_modelo)
29
 
30
- ## Generamos 4 mariposas
31
- n_mariposas = 4
 
32
 
33
- ## Funci贸n que genera mariposas y lo guarda como un estado de la sesi贸n
34
- def corre():
35
- with st.spinner("Generando, espera un poco..."):
36
- ims = genera(modelo_gan, n_mariposas)
37
- st.session_state["ims"] = ims
38
 
 
 
 
 
39
 
40
- ## Si no hay una imagen generada entonces generala
41
- if "ims" not in st.session_state:
42
- st.session_state["ims"] = None
43
- corre()
44
 
45
- ## ims contiene las im谩genes generadas
46
- ims = st.session_state["ims"]
47
 
48
- ## Si la usuaria da click en el bot贸n entonces corremos la funci贸n genera()
49
- corre_boton = st.button(
50
- "Genera mariposas, por favor.",
51
- on_click=corre,
52
- help="Estamos en pleno vuelo, puede tardar unos segundos.",
53
  )
54
 
55
  if ims is not None:
56
- cols = st.columns(n_mariposas)
57
  for j, im in enumerate(ims):
58
- i = j % n_mariposas
59
  cols[i].image(im, use_column_width=True)
 
1
  import streamlit as st
2
+ import os
3
 
4
+ from utils import load_model, generate
5
 
6
+ st.title('Image Generator with GAN')
7
+ st.markdown('Butterflies generator')
8
+
9
+ st.write("Token Access:", st.secrets["access_token"])
 
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ # Sidebar
13
+ st.sidebar.subheader('This butterfly does not exist, it is completely generated!')
14
+ st.sidebar.image('assets/logo.jpeg', width=200)
15
+ st.sidebar.caption('Demo was just created.')
16
 
17
+ # Loading model
18
+ repo_id = 'ceyda/butterfly_cropped_uniq1K_512'
19
+ gan_model = load_model(repo_id)
20
 
21
+ # Generate 4 butterflies
22
+ n_butterflies = 4
 
 
 
23
 
24
+ def run():
25
+ with st.spinner('Generating...'):
26
+ ims = generate(gan_model, n_butterflies)
27
+ st.session_state['ims'] = ims
28
 
29
+ if 'ims' not in st.session_state:
30
+ st.session_state['ims'] = None
31
+ run()
 
32
 
33
+ ims = st.session_state['ims']
 
34
 
35
+ run_button = st.button(
36
+ 'Generate butterflies',
37
+ on_click=run,
38
+ help='We are about to start to generate'
 
39
  )
40
 
41
  if ims is not None:
42
+ cols = st.columns(n_butterflies)
43
  for j, im in enumerate(ims):
44
+ i = j % n_butterflies
45
  cols[i].image(im, use_column_width=True)