Spaces:
Runtime error
Runtime error
rodragon737
commited on
Commit
•
1aa1d31
1
Parent(s):
ad3a7c1
refactory Utils
Browse files
app.py
CHANGED
@@ -1,40 +1,54 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
## Barra
|
10 |
-
st.sidebar.subheader("
|
11 |
st.sidebar.image("assets/logo.png", width=200)
|
12 |
-
st.sidebar.caption(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
##
|
15 |
repo_id = "ceyda/butterfly_cropped_uniq1K_512"
|
16 |
version_modelo = "57d36a15546909557d9f967f47713236c8288838"
|
17 |
modelo_gan = carga_modelo(repo_id, version_modelo)
|
18 |
|
19 |
-
##
|
20 |
n_mariposas = 4
|
21 |
|
22 |
-
##
|
23 |
def corre():
|
24 |
-
with st.spinner("
|
25 |
-
ims =
|
26 |
st.session_state["ims"] = ims
|
27 |
|
|
|
|
|
28 |
if "ims" not in st.session_state:
|
29 |
st.session_state["ims"] = None
|
30 |
corre()
|
31 |
|
|
|
32 |
ims = st.session_state["ims"]
|
33 |
|
|
|
34 |
corre_boton = st.button(
|
35 |
-
"
|
36 |
on_click=corre,
|
37 |
-
help="
|
38 |
)
|
39 |
|
40 |
if ims is not None:
|
|
|
1 |
import streamlit as st
|
2 |
+
from utils import carga_modelo, genera
|
3 |
|
4 |
+
## Página principal
|
5 |
+
st.title("Butterfly GAN (GAN de mariposas)")
|
6 |
+
st.write(
|
7 |
+
"Modelo Light-GAN entrenado con 1000 imágenes de mariposas tomadas de la colección del Museo Smithsonian."
|
8 |
+
)
|
9 |
|
10 |
+
## Barra lateral
|
11 |
+
st.sidebar.subheader("¡Esta mariposa no existe! Ni en América Latina 🤯.")
|
12 |
st.sidebar.image("assets/logo.png", width=200)
|
13 |
+
st.sidebar.caption(
|
14 |
+
f"[Modelo](https://huggingface.co/ceyda/butterfly_cropped_uniq1K_512) y [Dataset](https://huggingface.co/datasets/huggan/smithsonian_butterflies_subset) usados."
|
15 |
+
)
|
16 |
+
st.sidebar.caption(f"*Disclaimers:*")
|
17 |
+
st.sidebar.caption(
|
18 |
+
"* 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). Cualquier error se atribuye a [Omar Espejel](https://twitter.com/espejelomar)."
|
19 |
+
)
|
20 |
+
st.sidebar.caption(
|
21 |
+
"* Modelo basado en el [paper](https://openreview.net/forum?id=1Fqg133qRaI) *Towards Faster and Stabilized GAN Training for High-fidelity Few-shot Image Synthesis*."
|
22 |
+
)
|
23 |
|
24 |
+
## Cargamos modelo
|
25 |
repo_id = "ceyda/butterfly_cropped_uniq1K_512"
|
26 |
version_modelo = "57d36a15546909557d9f967f47713236c8288838"
|
27 |
modelo_gan = carga_modelo(repo_id, version_modelo)
|
28 |
|
29 |
+
## Generamos 4 mariposas
|
30 |
n_mariposas = 4
|
31 |
|
32 |
+
## Función que genera mariposas y lo guarda como un estado de la sesión
|
33 |
def corre():
|
34 |
+
with st.spinner("Generando, espera un poco..."):
|
35 |
+
ims = genera(modelo_gan, n_mariposas)
|
36 |
st.session_state["ims"] = ims
|
37 |
|
38 |
+
|
39 |
+
## Si no hay una imagen generada entonces generala
|
40 |
if "ims" not in st.session_state:
|
41 |
st.session_state["ims"] = None
|
42 |
corre()
|
43 |
|
44 |
+
## ims contiene las imágenes generadas
|
45 |
ims = st.session_state["ims"]
|
46 |
|
47 |
+
## Si la usuaria da click en el botón entonces corremos la función genera()
|
48 |
corre_boton = st.button(
|
49 |
+
"Genera mariposas, porfa.",
|
50 |
on_click=corre,
|
51 |
+
help="Estamos en pleno vuelo, puede tardar.",
|
52 |
)
|
53 |
|
54 |
if ims is not None:
|