Spaces:
Runtime error
Runtime error
Commit
路
df98ebc
1
Parent(s):
8422359
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,5 @@
|
|
1 |
-
# from distutils.command.build import build
|
2 |
import streamlit as st # HF spaces at v1.2.0
|
3 |
-
# from utils import load_model,generate,get_dataset,embed,make_meme
|
4 |
from utils import load_model,generate
|
5 |
-
# import streamlit.components.v1 as components
|
6 |
-
# import io
|
7 |
-
# import os
|
8 |
-
|
9 |
-
# root_dir=os.path.dirname(os.path.abspath(__file__))
|
10 |
-
# build_dir = os.path.join(root_dir, "custom_component/frontend/build")
|
11 |
-
# _component_func = components.declare_component("release_butterflies", path=build_dir)
|
12 |
-
# def release_butterflies(name, key=None):
|
13 |
-
# component_value = _component_func(name=name, key=key, default=0)
|
14 |
-
# return component_value
|
15 |
-
|
16 |
|
17 |
## Configuraci贸n de nuestro demo
|
18 |
st.title("Butterfly GAN (GAN de mariposas)")
|
@@ -21,59 +8,17 @@ st.write("*Disclaimers:")
|
|
21 |
st.write("* 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).")
|
22 |
st.write("* 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 |
-
st.sidebar.subheader("隆Esta mariposa no existe! Ni en Am茅rica Latina
|
25 |
st.sidebar.image("assets/logo.png", width=200)
|
26 |
-
st.sidebar.caption(f"[
|
27 |
-
st.sidebar.caption(f"
|
28 |
-
st.sidebar.caption(f"
|
29 |
-
st.sidebar.caption(f"[Ceyda Cinarel](https://github.com/cceyda) & [Jonathan Whitaker](https://datasciencecastnet.home.blog/)")
|
30 |
-
|
31 |
|
32 |
## Cargamos modelo
|
33 |
repo_id = 'ceyda/butterfly_cropped_uniq1K_512'
|
34 |
version_modelo ='57d36a15546909557d9f967f47713236c8288838'
|
35 |
modelo_gan = load_model(repo_id, version_modelo)
|
36 |
|
37 |
-
# @st.experimental_singleton
|
38 |
-
# def load_model_intocache(model_name,model_version):
|
39 |
-
# # model_name='ceyda/butterfly_512_base'
|
40 |
-
# gan = load_model(model_name,model_version)
|
41 |
-
# return gan
|
42 |
-
|
43 |
-
# @st.experimental_singleton
|
44 |
-
# def load_dataset():
|
45 |
-
# dataset=get_dataset()
|
46 |
-
# return dataset
|
47 |
-
|
48 |
-
# @st.experimental_singleton
|
49 |
-
# def load_variables():# Don't want to open read files over and over. not sure if it makes a diff
|
50 |
-
# latent_walk_code=open("assets/code_snippets/latent_walk.py").read()
|
51 |
-
# latent_walk_code_music=open("assets/code_snippets/latent_walk_music.py").read()
|
52 |
-
# return latent_walk_code,latent_walk_code_music
|
53 |
-
|
54 |
-
# def img2download(image):
|
55 |
-
# imgByteArr = io.BytesIO()
|
56 |
-
# image.save(imgByteArr, format="JPEG")
|
57 |
-
# imgByteArr = imgByteArr.getvalue()
|
58 |
-
# return imgByteArr
|
59 |
-
|
60 |
-
# model_name='ceyda/butterfly_cropped_uniq1K_512'
|
61 |
-
# model_version='57d36a15546909557d9f967f47713236c8288838'
|
62 |
-
# model_version=None
|
63 |
-
|
64 |
-
|
65 |
-
# model=load_model_intocache(model_name,model_version)
|
66 |
-
# dataset=loadk_dataset()
|
67 |
-
# latent_walk_code, latent_walk_code_music=load_variables()
|
68 |
-
|
69 |
-
# generate_menu="馃 Make butterflies"
|
70 |
-
# latent_walk_menu="馃帶 Take a latent walk"
|
71 |
-
# make_meme_menu="馃惁 Make a meme"
|
72 |
-
# mosaic_menu="馃憖 See the mosaic"
|
73 |
-
# fun_menu="馃檶 Release the butterflies"
|
74 |
-
|
75 |
-
# screen = st.sidebar.radio("Pick a destination",[generate_menu,latent_walk_menu,make_meme_menu,mosaic_menu,fun_menu])
|
76 |
-
|
77 |
## Generamos 4 mariposas
|
78 |
n_mariposas =4
|
79 |
|
@@ -92,7 +37,7 @@ if 'ims' not in st.session_state:
|
|
92 |
ims=st.session_state["ims"]
|
93 |
|
94 |
## Si la usuaria da click en el bot贸n entonces corremos la funci贸n genera()
|
95 |
-
runb=st.button("Genera mariposas
|
96 |
|
97 |
if ims is not None:
|
98 |
cols=st.columns(n_mariposas)
|
@@ -100,81 +45,5 @@ if ims is not None:
|
|
100 |
for j,im in enumerate(ims):
|
101 |
i=j%n_mariposas
|
102 |
cols[i].image(im, use_column_width=True)
|
103 |
-
# picks[j]=cols[i].button("Find Nearest",key="pick_"+str(j))
|
104 |
-
|
105 |
-
# if any(picks):
|
106 |
-
# # st.write("Nearest butterflies:")
|
107 |
-
# for i,pick in enumerate(picks):
|
108 |
-
# if pick:
|
109 |
-
# scores, retrieved_examples=dataset.get_nearest_examples('beit_embeddings', embed(ims[i]), k=5)
|
110 |
-
# for r in retrieved_examples["image"]:
|
111 |
-
# cols[i].image(r, use_column_width=True)
|
112 |
-
# st.write("Nearest neighbors found in the training set according to L2 distance on 'microsoft/beit-base-patch16-224' embeddings")
|
113 |
-
# st.write(f"Latent dimension: {model.latent_dim}, image size:{model.image_size}")
|
114 |
-
|
115 |
-
# elif screen == latent_walk_menu:
|
116 |
-
|
117 |
-
# st.write("Take a latent walk :musical_note: with cute butterflies")
|
118 |
-
|
119 |
-
# cols=st.columns(3)
|
120 |
-
|
121 |
-
# cols[0].caption("A regular walk (no music)")
|
122 |
-
# cols[0].video("assets/latent_walks/regular_walk.mp4")
|
123 |
-
|
124 |
-
# cols[1].caption("Walk with music :butterfly:")
|
125 |
-
# cols[1].video("assets/latent_walks/walk_happyrock.mp4")
|
126 |
-
# cols[2].caption("Walk with music :butterfly:")
|
127 |
-
# cols[2].video("assets/latent_walks/walk_cute.mp4")
|
128 |
-
|
129 |
-
# st.caption("Royalty Free Music from Bensound")
|
130 |
-
# st.write("馃帶Did those butterflies seem to be dancing to the music?!Here is the secret:")
|
131 |
-
# with st.expander("See the Code Snippets"):
|
132 |
-
# st.write("A regular latent walk:")
|
133 |
-
# st.code(latent_walk_code, language='python')
|
134 |
-
# st.write(":musical_note: latent walk with music:")
|
135 |
-
# st.code(latent_walk_code_music, language='python')
|
136 |
-
|
137 |
-
|
138 |
-
# elif screen == make_meme_menu:
|
139 |
-
# if "pigeon" not in st.session_state:
|
140 |
-
# st.session_state['pigeon'] = generate(model,1)[0]
|
141 |
-
|
142 |
-
# def get_pigeon():
|
143 |
-
# st.session_state['pigeon'] = generate(model,1)[0]
|
144 |
-
|
145 |
-
# cols= st.columns(2)
|
146 |
-
# cols[0].button("change pigeon",on_click=get_pigeon)
|
147 |
-
# no_bg=cols[1].checkbox("Remove background?",True,help="Remove the background from pigeon")
|
148 |
-
# show_text=cols[1].checkbox("Show text?",True)
|
149 |
-
|
150 |
-
# meme_text=st.text_input("Enter text","Is this a pigeon?")
|
151 |
-
|
152 |
-
|
153 |
-
# meme=make_meme(st.session_state['pigeon'],text=meme_text,show_text=show_text,remove_background=no_bg)
|
154 |
-
# st.image(meme)
|
155 |
-
# coly=st.columns(2)
|
156 |
-
# coly[0].download_button("Download", img2download(meme),mime="image/jpeg")
|
157 |
-
# coly[1].write("Made a cool one? [Share](https://twitter.com/intent/tweet?text=Check%20out%20the%20demo%20for%20Butterfly%20GAN%20%F0%9F%A6%8Bhttps%3A//huggingface.co/spaces/huggan/butterfly-gan%0Amade%20by%20%40ceyda_cinarel%20%26%20%40johnowhitaker%20) on Twitter")
|
158 |
-
|
159 |
-
|
160 |
-
# elif screen == mosaic_menu:
|
161 |
-
# cols=st.columns(2)
|
162 |
-
# cols[0].markdown("These are all the butterflies in our [training set](https://huggingface.co/huggan/smithsonian_butterflies_subset)")
|
163 |
-
# cols[0].image("assets/train_data_mosaic_lowres.jpg")
|
164 |
-
# cols[0].write("馃攷 view the high-res version [here](https://www.easyzoom.com/imageaccess/0c77e0e716f14ea7bc235447e5a4c397)")
|
165 |
-
|
166 |
-
# cols[1].markdown("These are the butterflies our model generated.")
|
167 |
-
# cols[1].image("assets/gen_mosaic_lowres.jpg")
|
168 |
-
# cols[1].write("馃攷 view the high-res version [here](https://www.easyzoom.com/imageaccess/cbb04e81106c4c54a9d9f9dbfb236eab)")
|
169 |
|
170 |
-
# elif screen == fun_menu:
|
171 |
-
|
172 |
-
# cols=st.columns([1,2])
|
173 |
-
# cols[0].write("While working on this project")
|
174 |
-
# cols[0].image("assets/butterflies_everywhere.jpg")
|
175 |
-
|
176 |
-
# with cols[1]:
|
177 |
-
# release_butterflies("Hello World")
|
178 |
-
|
179 |
|
180 |
-
## Feel free to add more & change stuff ^
|
|
|
|
|
1 |
import streamlit as st # HF spaces at v1.2.0
|
|
|
2 |
from utils import load_model,generate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
## Configuraci贸n de nuestro demo
|
5 |
st.title("Butterfly GAN (GAN de mariposas)")
|
|
|
8 |
st.write("* 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).")
|
9 |
st.write("* Modelo basado en el [paper](https://openreview.net/forum?id=1Fqg133qRaI) *Towards Faster and Stabilized GAN Training for High-fidelity Few-shot Image Synthesis*.")
|
10 |
|
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(f"[Modelo](https://huggingface.co/ceyda/butterfly_cropped_uniq1K_512) y [Dataset](https://huggingface.co/datasets/huggan/smithsonian_butterflies_subset) usados.")
|
14 |
+
st.sidebar.caption(f"*Contribuidores:*")
|
15 |
+
st.sidebar.caption(f"[Ceyda Cinarel](https://github.com/cceyda) y [Jonathan Whitaker](https://datasciencecastnet.home.blog/). Edici贸n de versi贸n simplificada por [Omar Espejel](https://twitter.com/espejelomar).")
|
|
|
|
|
16 |
|
17 |
## Cargamos modelo
|
18 |
repo_id = 'ceyda/butterfly_cropped_uniq1K_512'
|
19 |
version_modelo ='57d36a15546909557d9f967f47713236c8288838'
|
20 |
modelo_gan = load_model(repo_id, version_modelo)
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
## Generamos 4 mariposas
|
23 |
n_mariposas =4
|
24 |
|
|
|
37 |
ims=st.session_state["ims"]
|
38 |
|
39 |
## Si la usuaria da click en el bot贸n entonces corremos la funci贸n genera()
|
40 |
+
runb=st.button("Genera mariposas, porfa.", on_click=corre ,help="Estamos en pleno vuelo, puede tardar.")
|
41 |
|
42 |
if ims is not None:
|
43 |
cols=st.columns(n_mariposas)
|
|
|
45 |
for j,im in enumerate(ims):
|
46 |
i=j%n_mariposas
|
47 |
cols[i].image(im, use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
|