Spaces:
Runtime error
Runtime error
removed magic !pip installs
Browse files
app.py
CHANGED
@@ -7,10 +7,14 @@ Original file is located at
|
|
7 |
https://colab.research.google.com/drive/1ckZU76dq3XWcpa5PpQF8a6qJwkTttg8v
|
8 |
|
9 |
# ⚙️ Setup
|
10 |
-
|
11 |
-
## Fix random seeds
|
12 |
"""
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
SEED = 11
|
15 |
import os
|
16 |
os.environ['PYTHONHASHSEED']=str(SEED)
|
@@ -24,46 +28,22 @@ tf.random.set_seed(SEED)
|
|
24 |
|
25 |
"""## Imports"""
|
26 |
|
27 |
-
!pip install gradio -q
|
28 |
-
|
29 |
import gradio as gr
|
30 |
-
|
31 |
-
from scipy import linalg
|
32 |
-
import matplotlib.pyplot as plt
|
33 |
import pandas as pd
|
34 |
-
|
35 |
-
from tensorflow import keras
|
36 |
-
from tensorflow.keras import layers
|
37 |
-
from keras.applications.inception_v3 import InceptionV3, preprocess_input
|
38 |
-
|
39 |
-
from tensorflow.keras.layers import Layer, Input, Dense, Reshape, Flatten
|
40 |
-
from tensorflow.keras.layers import Conv2D, Conv2DTranspose, ReLU, LeakyReLU
|
41 |
-
from tensorflow.keras.layers import Dropout, Embedding, Concatenate, Add, Activation
|
42 |
-
from tensorflow.keras.layers import GlobalAveragePooling2D, UpSampling2D, BatchNormalization
|
43 |
-
import tensorflow.keras.backend as K
|
44 |
-
|
45 |
-
from tensorflow.python.keras.utils import conv_utils
|
46 |
-
from tensorflow.keras.initializers import RandomNormal
|
47 |
-
from tensorflow.keras.optimizers import Adam
|
48 |
-
|
49 |
-
!pip install tensorflow_addons
|
50 |
-
import tensorflow_addons as tfa
|
51 |
-
from tensorflow_addons.layers import SpectralNormalization
|
52 |
-
|
53 |
import gdown
|
54 |
from zipfile import ZipFile
|
55 |
|
56 |
-
from tqdm.notebook import tqdm
|
57 |
-
|
58 |
"""## Download CelebA attributes
|
59 |
|
60 |
We'll use face images from the CelebA dataset, resized to 64x64.
|
61 |
"""
|
62 |
|
63 |
#Download labels from public github, they have been processed in a 0,1 csv file
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
67 |
|
68 |
"""## Dataset preprocessing functions"""
|
69 |
|
@@ -127,12 +107,13 @@ acgan40_hd = ModelEntry('buio','booicugb','acgan10_nonseparBNstdev_split_299_218
|
|
127 |
#2o3z6bqb SAGAN_5 v17 buianifolli
|
128 |
#zscel8bz SAGAN_6 v29 buianifolli
|
129 |
|
|
|
130 |
#sagan40 v18
|
131 |
|
132 |
-
keras_metadata_url = "https://api.wandb.ai/artifactsV2/gcp-us/buianifolli/QXJ0aWZhY3Q6Mjg3MzA4NTY=/5f09f68e9bb5b09efbc37ad76cdcdbb0"
|
133 |
-
saved_model_url = "https://api.wandb.ai/artifactsV2/gcp-us/buianifolli/QXJ0aWZhY3Q6Mjg3NDY1OTU=/2676cd88ef1866d6e572916e413a933e"
|
134 |
-
variables_url = "https://api.wandb.ai/artifactsV2/gcp-us/buianifolli/QXJ0aWZhY3Q6Mjg3NDY1OTU=/5cab1cb7351f0732ea137fb2d2e0d4ec"
|
135 |
-
index_url = "https://api.wandb.ai/artifactsV2/gcp-us/buianifolli/QXJ0aWZhY3Q6Mjg3NDY1OTU=/480b55762c3358f868b8cce53984736b"
|
136 |
|
137 |
#sagan10 v16
|
138 |
|
@@ -141,9 +122,6 @@ saved_model_url = "https://api.wandb.ai/artifactsV2/gcp-us/buianifolli/QXJ0aWZhY
|
|
141 |
variables_url = "https://api.wandb.ai/artifactsV2/gcp-us/buianifolli/QXJ0aWZhY3Q6MjYxMzQ0Mjg=/a62bf0c4bf7047c0a31df7d2cfdb54f0"
|
142 |
index_url = "https://api.wandb.ai/artifactsV2/gcp-us/buianifolli/QXJ0aWZhY3Q6MjYxMzQ0Mjg=/de6539a7f0909d1dafa89571c7df43d1"
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
#download model
|
148 |
gan_path = "/content/gan_model/"
|
149 |
try:
|
@@ -157,7 +135,7 @@ os.makedirs(gan_path,exist_ok =True)
|
|
157 |
os.makedirs(gan_path+"/variables",exist_ok =True)
|
158 |
|
159 |
|
160 |
-
|
161 |
import wget
|
162 |
wget.download(keras_metadata_url, gan_path+"keras_metadata.pb",)
|
163 |
wget.download(saved_model_url, gan_path+"saved_model.pb")
|
@@ -243,28 +221,4 @@ iface = gr.Interface(
|
|
243 |
"image",
|
244 |
layout='unaligned'
|
245 |
)
|
246 |
-
iface.launch(debug=True)
|
247 |
-
|
248 |
-
def sentence_builder(quantity, animal, place, activity_list, morning):
|
249 |
-
return f"""The {quantity} {animal}s went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}"""
|
250 |
-
|
251 |
-
def generate_image(attributes)
|
252 |
-
|
253 |
-
iface = gr.Interface(
|
254 |
-
sentence_builder,
|
255 |
-
[
|
256 |
-
gr.inputs.Slider(2, 20),
|
257 |
-
gr.inputs.Dropdown(["cat", "dog", "bird"]),
|
258 |
-
gr.inputs.Radio(["park", "zoo", "road"]),
|
259 |
-
gr.inputs.CheckboxGroup(["ran", "swam", "ate", "slept"]),
|
260 |
-
gr.inputs.Checkbox(label="Is it the morning?"),
|
261 |
-
],
|
262 |
-
"text",
|
263 |
-
examples=[
|
264 |
-
[2, "cat", "park", ["ran", "swam"], True],
|
265 |
-
[4, "dog", "zoo", ["ate", "swam"], False],
|
266 |
-
[10, "bird", "road", ["ran"], False],
|
267 |
-
[8, "cat", "zoo", ["ate"], True],
|
268 |
-
],
|
269 |
-
)
|
270 |
iface.launch()
|
|
|
7 |
https://colab.research.google.com/drive/1ckZU76dq3XWcpa5PpQF8a6qJwkTttg8v
|
8 |
|
9 |
# ⚙️ Setup
|
|
|
|
|
10 |
"""
|
11 |
|
12 |
+
#!pip install gradio -q
|
13 |
+
#!pip install wget -q
|
14 |
+
#!pip install tensorflow_addons -q
|
15 |
+
|
16 |
+
"""## Fix random seeds"""
|
17 |
+
|
18 |
SEED = 11
|
19 |
import os
|
20 |
os.environ['PYTHONHASHSEED']=str(SEED)
|
|
|
28 |
|
29 |
"""## Imports"""
|
30 |
|
|
|
|
|
31 |
import gradio as gr
|
32 |
+
import wget
|
|
|
|
|
33 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
import gdown
|
35 |
from zipfile import ZipFile
|
36 |
|
|
|
|
|
37 |
"""## Download CelebA attributes
|
38 |
|
39 |
We'll use face images from the CelebA dataset, resized to 64x64.
|
40 |
"""
|
41 |
|
42 |
#Download labels from public github, they have been processed in a 0,1 csv file
|
43 |
+
os.mkdir("/content/celeba_gan")
|
44 |
+
wget.download(url="https://github.com/buoi/conditional-face-GAN/blob/main/list_attr_celeba01.csv.zip?raw=true", out="/content/celeba_gan/list_attr_celeba01.csv.zip")
|
45 |
+
import shutil
|
46 |
+
shutil.unpack_archive(filename="/content/celeba_gan/list_attr_celeba01.csv.zip", extract_dir="/content/celeba_gan")
|
47 |
|
48 |
"""## Dataset preprocessing functions"""
|
49 |
|
|
|
107 |
#2o3z6bqb SAGAN_5 v17 buianifolli
|
108 |
#zscel8bz SAGAN_6 v29 buianifolli
|
109 |
|
110 |
+
#wandb artifacts
|
111 |
#sagan40 v18
|
112 |
|
113 |
+
#keras_metadata_url = "https://api.wandb.ai/artifactsV2/gcp-us/buianifolli/QXJ0aWZhY3Q6Mjg3MzA4NTY=/5f09f68e9bb5b09efbc37ad76cdcdbb0"
|
114 |
+
#saved_model_url = "https://api.wandb.ai/artifactsV2/gcp-us/buianifolli/QXJ0aWZhY3Q6Mjg3NDY1OTU=/2676cd88ef1866d6e572916e413a933e"
|
115 |
+
#variables_url = "https://api.wandb.ai/artifactsV2/gcp-us/buianifolli/QXJ0aWZhY3Q6Mjg3NDY1OTU=/5cab1cb7351f0732ea137fb2d2e0d4ec"
|
116 |
+
#index_url = "https://api.wandb.ai/artifactsV2/gcp-us/buianifolli/QXJ0aWZhY3Q6Mjg3NDY1OTU=/480b55762c3358f868b8cce53984736b"
|
117 |
|
118 |
#sagan10 v16
|
119 |
|
|
|
122 |
variables_url = "https://api.wandb.ai/artifactsV2/gcp-us/buianifolli/QXJ0aWZhY3Q6MjYxMzQ0Mjg=/a62bf0c4bf7047c0a31df7d2cfdb54f0"
|
123 |
index_url = "https://api.wandb.ai/artifactsV2/gcp-us/buianifolli/QXJ0aWZhY3Q6MjYxMzQ0Mjg=/de6539a7f0909d1dafa89571c7df43d1"
|
124 |
|
|
|
|
|
|
|
125 |
#download model
|
126 |
gan_path = "/content/gan_model/"
|
127 |
try:
|
|
|
135 |
os.makedirs(gan_path+"/variables",exist_ok =True)
|
136 |
|
137 |
|
138 |
+
|
139 |
import wget
|
140 |
wget.download(keras_metadata_url, gan_path+"keras_metadata.pb",)
|
141 |
wget.download(saved_model_url, gan_path+"saved_model.pb")
|
|
|
221 |
"image",
|
222 |
layout='unaligned'
|
223 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
iface.launch()
|