Spaces:
Sleeping
Sleeping
File size: 1,875 Bytes
d717c03 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import streamlit as st
from utils import load_model, generate
## Title and write
st.title("Butterfly GAN")
st.write(
"Light-GAN model trained with 1000 butterfly images taken from the Smithsonian Museum collection."
)
## Sidebar
st.sidebar.subheader("This butterfly does not exist!.")
st.sidebar.image("assets/logo.png", width=200)
st.sidebar.caption(
f"[Model](https://huggingface.co/ceyda/butterfly_cropped_uniq1K_512) and [Dataset](https://huggingface.co/datasets/huggan/smithsonian_butterflies_subset) used."
)
st.sidebar.caption(f"*Disclaimers:*")
st.sidebar.caption(
"* This demo is a simplified version of the one created by [Ceyda Cinarel](https://github.com/cceyda) and [Jonathan Whitaker](https://datasciencecastnet.home.blog/) ([link](https://huggingface.co/spaces/huggan/butterfly-gan)) during the hackathon [HugGan](https://github.com/huggingface/community-events)."
)
st.sidebar.caption(
"* Model based on [paper](https://openreview.net/forum?id=1Fqg133qRaI) *Towards Faster and Stabilized GAN Training for High-fidelity Few-shot Image Synthesis*."
)
## Load model
repo_id = "ceyda/butterfly_cropped_uniq1K_512"
version_model = "57d36a15546909557d9f967f47713236c8288838"
model_gan = load_model(repo_id, version_model)
n_mariposas = 4
## Function that generates butterflies and saves it as a state of the session
def run():
with st.spinner("Generating, wait a little..."):
ims = generate(model_gan, n_mariposas)
st.session_state["ims"] = ims
if "ims" not in st.session_state:
st.session_state["ims"] = None
run()
ims = st.session_state["ims"]
run_boton = st.button(
"Spawn butterflies.",
on_click=run,
help="Generate images.",
)
if ims is not None:
cols = st.columns(n_mariposas)
for j, im in enumerate(ims):
i = j % n_mariposas
cols[i].image(im, use_column_width=True) |