Ceyda Cinarel commited on
Commit
cb5f8d1
1 Parent(s): e122c50

add logo and menus

Browse files
Files changed (3) hide show
  1. app.py +51 -40
  2. assets/logo.png +0 -0
  3. assets/training_data_lowres.png +0 -0
app.py CHANGED
@@ -4,22 +4,19 @@ from demo import load_model,generate,get_dataset,embed
4
 
5
  # TODOs
6
  # Add markdown short readme project intro
7
- # project setup:
8
-
9
- # git clone https://github.com/huggingface/community-events.git
10
- # cd community-events
11
- # pip install .
12
-
13
- st.title("ButterflyGAN")
14
- st.write("## This butterfly does not exist! ")
15
  st.write("Demo prep still in progress!!")
16
 
 
17
  @st.experimental_singleton
18
  def load_model_intocache(model_name):
19
 
20
  # model_name='ceyda/butterfly_512_base'
21
  gan = load_model(model_name)
22
-
23
  return gan
24
 
25
  @st.experimental_singleton
@@ -31,37 +28,51 @@ model_name='ceyda/butterfly_cropped_uniq1K_512'
31
  model=load_model_intocache(model_name)
32
  dataset=load_dataset()
33
 
34
- st.write(f"Model {model_name} is loaded")
35
- st.write(f"Latent dimension: {model.latent_dim}, Image size:{model.image_size}")
36
-
37
- if 'ims' not in st.session_state:
38
- st.session_state['ims'] = None
39
-
40
- ims=st.session_state["ims"]
41
- batch_size=4 #generate 4 butterflies
42
- def run():
43
- with st.spinner("Generating..."):
44
- ims=generate(model,batch_size)
45
- st.session_state['ims'] = ims
46
-
47
- runb=st.button("Generate", on_click=run)
48
- if ims is not None:
49
- cols=st.columns(batch_size)
50
- picks=[False]*batch_size
51
- for i,im in enumerate(ims):
52
- cols[i].image(im)
53
- picks[i]=cols[i].button("Find Nearest",key="pick_"+str(i))
54
- # if picks[i]:
55
- # scores, retrieved_examples=dataset.get_nearest_examples('beit_embeddings', embed(im), k=5)
56
- # for r in retrieved_examples["image"]:
57
- # st.image(r)
58
 
59
- if any(picks):
60
- # st.write("Nearest butterflies:")
61
- for i,pick in enumerate(picks):
62
- if pick:
63
- scores, retrieved_examples=dataset.get_nearest_examples('beit_embeddings', embed(ims[i]), k=5)
64
- for r in retrieved_examples["image"]:
65
- cols[i].image(r)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
 
 
 
 
4
 
5
  # TODOs
6
  # Add markdown short readme project intro
7
+
8
+
9
+ st.sidebar.image("assets/logo.png", use_column_width=True)
10
+ st.header("ButterflyGAN")
11
+ st.caption("This butterfly does not exist! ")
 
 
 
12
  st.write("Demo prep still in progress!!")
13
 
14
+
15
  @st.experimental_singleton
16
  def load_model_intocache(model_name):
17
 
18
  # model_name='ceyda/butterfly_512_base'
19
  gan = load_model(model_name)
 
20
  return gan
21
 
22
  @st.experimental_singleton
 
28
  model=load_model_intocache(model_name)
29
  dataset=load_dataset()
30
 
31
+ screen = st.sidebar.radio("Pick a destination",["Make butterflies","Take a latent walk", "See the data mosaic"])
32
+
33
+ if screen == "Make butterflies":
34
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
+
37
+ if 'ims' not in st.session_state:
38
+ st.session_state['ims'] = None
39
+
40
+ ims=st.session_state["ims"]
41
+ batch_size=4 #generate 4 butterflies
42
+ def run():
43
+ with st.spinner("Generating..."):
44
+ ims=generate(model,batch_size)
45
+ st.session_state['ims'] = ims
46
+
47
+ runb=st.button("Generate", on_click=run)
48
+ if ims is not None:
49
+ cols=st.columns(batch_size)
50
+ picks=[False]*batch_size
51
+ for i,im in enumerate(ims):
52
+ cols[i].image(im)
53
+ picks[i]=cols[i].button("Find Nearest",key="pick_"+str(i))
54
+ # if picks[i]:
55
+ # scores, retrieved_examples=dataset.get_nearest_examples('beit_embeddings', embed(im), k=5)
56
+ # for r in retrieved_examples["image"]:
57
+ # st.image(r)
58
+
59
+ if any(picks):
60
+ # st.write("Nearest butterflies:")
61
+ for i,pick in enumerate(picks):
62
+ if pick:
63
+ scores, retrieved_examples=dataset.get_nearest_examples('beit_embeddings', embed(ims[i]), k=5)
64
+ for r in retrieved_examples["image"]:
65
+ cols[i].image(r)
66
+
67
+ st.write(f"Latent dimension: {model.latent_dim}, Image size:{model.image_size}")
68
+
69
+ elif screen == "Take a latent walk":
70
+ st.write("Take a latent walk")
71
+
72
+ elif screen == "Input data mosaic":
73
+ st.markdown("Todo add explanation about data")
74
+ st.image("assets/training_data_lowres.png")
75
 
76
 
77
+ # footer stuff
78
+ st.sidebar.info(f"Model {model_name} is loaded")
assets/logo.png ADDED
assets/training_data_lowres.png ADDED