Spaces:
Sleeping
Sleeping
fix
Browse files- bin/Dockerfile +17 -0
- bin/_env.sh +60 -0
- bin/server.py +59 -0
bin/Dockerfile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM guillaumeai/ast:picasso
|
| 2 |
+
|
| 3 |
+
RUN apt update
|
| 4 |
+
RUN apt upgrade -y
|
| 5 |
+
|
| 6 |
+
RUN pip install -U pip
|
| 7 |
+
#RUN pip install -U pyyaml
|
| 8 |
+
RUN pip install -U runway-python
|
| 9 |
+
#runway --force-reinstall
|
| 10 |
+
#RUN pip install -U tensorflow
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
COPY server.py .
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
CMD ["python", "server.py"]
|
bin/_env.sh
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ctlid=2403272038
|
| 2 |
+
dockertag=jgwill/dev:astpicasso
|
| 3 |
+
|
| 4 |
+
containername=astpicasso
|
| 5 |
+
dkhostname=$containername
|
| 6 |
+
|
| 7 |
+
# PORT
|
| 8 |
+
dkport=7860:7860
|
| 9 |
+
|
| 10 |
+
#xmount=/tmp:/a/tmp
|
| 11 |
+
#xmount2=/var:/a/var
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
dkcommand=bash #command to execute (default is the one in the dockerfile)
|
| 15 |
+
|
| 16 |
+
#dkextra=" -v \$dworoot/x:/x -p 2288:2288 "
|
| 17 |
+
|
| 18 |
+
#dkmounthome=true
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
##########################
|
| 22 |
+
############# RUN MODE
|
| 23 |
+
#dkrunmode="bg" #default fg
|
| 24 |
+
#dkrestart="--restart" #default
|
| 25 |
+
#dkrestarttype="unless-stopped" #default
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
#########################################
|
| 29 |
+
################## VOLUMES
|
| 30 |
+
#dkvolume="myvolname220413:/app" #create or use existing one
|
| 31 |
+
#dkvolume="$containername:/app" #create with containername name
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
#dkecho=true #just echo the docker run
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# Use TZ
|
| 39 |
+
#DK_TZ=1
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
#####################################
|
| 44 |
+
#Build related
|
| 45 |
+
#
|
| 46 |
+
##chg back to that user
|
| 47 |
+
#dkchguser=vscode
|
| 48 |
+
|
| 49 |
+
######################## HOOKS BASH
|
| 50 |
+
### IF THEY EXIST, THEY are Executed, you can change their names
|
| 51 |
+
|
| 52 |
+
dkbuildprebuildscript=dkbuildprebuildscript.sh
|
| 53 |
+
dkbuildbuildsuccessscript=dkbuildbuildsuccessscript.sh
|
| 54 |
+
dkbuildfailedscript=dkbuildfailedscript.sh
|
| 55 |
+
dkbuildpostbuildscript=dkbuildpostbuildscript.sh
|
| 56 |
+
|
| 57 |
+
###########################################
|
| 58 |
+
# Unset deprecated
|
| 59 |
+
unset DOCKER_BUILDKIT
|
| 60 |
+
|
bin/server.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import numpy as np
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
from module import encoder, decoder
|
| 5 |
+
from glob import glob
|
| 6 |
+
import runway
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@runway.setup(options={"styleCheckpoint": runway.file(is_directory=True)})
|
| 10 |
+
def setup(opts):
|
| 11 |
+
sess = tf.Session()
|
| 12 |
+
init_op = tf.global_variables_initializer()
|
| 13 |
+
sess.run(init_op)
|
| 14 |
+
with tf.name_scope("placeholder"):
|
| 15 |
+
input_photo = tf.placeholder(
|
| 16 |
+
dtype=tf.float32, shape=[1, None, None, 3], name="photo"
|
| 17 |
+
)
|
| 18 |
+
input_photo_features = encoder(
|
| 19 |
+
image=input_photo, options={"gf_dim": 32}, reuse=False
|
| 20 |
+
)
|
| 21 |
+
output_photo = decoder(
|
| 22 |
+
features=input_photo_features, options={"gf_dim": 32}, reuse=False
|
| 23 |
+
)
|
| 24 |
+
saver = tf.train.Saver()
|
| 25 |
+
path = opts["styleCheckpoint"]
|
| 26 |
+
model_name = [p for p in os.listdir(path) if os.path.isdir(os.path.join(path, p))][
|
| 27 |
+
0
|
| 28 |
+
]
|
| 29 |
+
checkpoint_dir = os.path.join(path, model_name, "checkpoint_long")
|
| 30 |
+
ckpt = tf.train.get_checkpoint_state(checkpoint_dir)
|
| 31 |
+
ckpt_name = os.path.basename(ckpt.model_checkpoint_path)
|
| 32 |
+
saver.restore(sess, os.path.join(checkpoint_dir, ckpt_name))
|
| 33 |
+
return dict(sess=sess, input_photo=input_photo, output_photo=output_photo)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
@runway.command(
|
| 37 |
+
"stylize",
|
| 38 |
+
inputs={"contentImage": runway.image},
|
| 39 |
+
outputs={"stylizedImage": runway.image},
|
| 40 |
+
)
|
| 41 |
+
def stylize(model, inp):
|
| 42 |
+
img = inp["contentImage"]
|
| 43 |
+
img = np.array(img)
|
| 44 |
+
img = img / 127.5 - 1.0
|
| 45 |
+
img = np.expand_dims(img, axis=0)
|
| 46 |
+
img = model["sess"].run(
|
| 47 |
+
model["output_photo"], feed_dict={model["input_photo"]: img}
|
| 48 |
+
)
|
| 49 |
+
img = (img + 1.0) * 127.5
|
| 50 |
+
img = img.astype("uint8")
|
| 51 |
+
img = img[0]
|
| 52 |
+
return dict(stylizedImage=img)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
#print("External Service port is:" + os.environ.get("SPORT",7860))
|
| 57 |
+
#set env var: RW_PORT=7860
|
| 58 |
+
os.environ["RW_PORT"] = "7860"
|
| 59 |
+
runway.run()
|