Spaces:
Runtime error
Runtime error
subiendo cambios
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
from utils import load_model,generate
|
4 |
+
|
5 |
+
st.title("butterfly_generator")
|
6 |
+
st.write("this is a ligth GAN generator model")
|
7 |
+
|
8 |
+
st.sidebar.subheader("this butterfly is created by IA")
|
9 |
+
st.sidebar.image("assets/logo.png",width=200)
|
10 |
+
|
11 |
+
model_id="ceyda/butterfly_cropped_uniq1K_512"
|
12 |
+
model_gan=load_model(model_id)
|
13 |
+
n_fly=4
|
14 |
+
def run():
|
15 |
+
with st.spinner("generating"):
|
16 |
+
ims=generate(model_gan,n_fly)
|
17 |
+
st.session_state["ims"]=ims
|
18 |
+
|
19 |
+
if "ims" not in st.session_state:
|
20 |
+
st.session_state["ims"]=None
|
21 |
+
run()
|
22 |
+
|
23 |
+
ims=st.session_state["ims"]
|
24 |
+
|
25 |
+
run_button=st.button(
|
26 |
+
"click me",
|
27 |
+
on_click=run
|
28 |
+
)
|
29 |
+
|
30 |
+
if ims is not None:
|
31 |
+
cols=st.columns(n_fly)
|
32 |
+
for j, im in enumerate(ims):
|
33 |
+
i=j%n_fly
|
34 |
+
cols[i].image(im,use_column_width=True)
|
utils.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import torch
|
3 |
+
from huggan.pytorch.lightweight_gan.lightweight_gan import LightweightGAN
|
4 |
+
|
5 |
+
def load_model(model_name="ceyda/butterfly_cropped_uniq1K_512", model_version=None):
|
6 |
+
gan=LightweightGAN.from_pretrained(model_name,version=model_version)
|
7 |
+
gan.eval()
|
8 |
+
return gan
|
9 |
+
|
10 |
+
def generate(gan,batch_size=1):
|
11 |
+
with torch.no_grad():
|
12 |
+
ims=gan.G(torch.randn(batch_size,gan.latent_dim)).clamp(0.0,1.0)*255
|
13 |
+
ims=ims.permute(0,2,3,1).deatch().cpu().numpy().astype(np.uint8)
|
14 |
+
return ims
|