Skip to content

Commit

Permalink
Wotd bot
Browse files Browse the repository at this point in the history
  • Loading branch information
turtlesoupy committed Jan 12, 2021
1 parent e0b1f07 commit 965405f
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
6 changes: 6 additions & 0 deletions deploy/website/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,10 @@ http {
server_name thisworddoesnotexist.com;
return 301 https://www.thisworddoesnotexist.com$request_uri;
}

server {
listen 8080;
server_name thisslangdoesnotexist.com;
return 301 https://www.thisslangdoesnotexist.com$request_uri;
}
}
5 changes: 4 additions & 1 deletion deploy/website/website-certificate-www.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
apiVersion: networking.gke.io/v1beta1
apiVersion: networking.gke.io/v1beta2
kind: ManagedCertificate
metadata:
name: website-certificate-www
spec:
domains:
- www.thisworddoesnotexist.com
- thisworddoesnotexist.com
- thisslangdoesnotexist.com
- www.thisslangdoesnotexist.com
2 changes: 1 addition & 1 deletion deploy/website/website-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
run: website
spec:
containers:
- image: gcr.io/this-word-does-not-exist/website:v74
- image: gcr.io/this-word-does-not-exist/website:v75
imagePullPolicy: IfNotPresent
name: website
ports:
Expand Down
2 changes: 1 addition & 1 deletion notebooks/fooling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.7.6"
}
},
"nbformat": 4,
Expand Down
83 changes: 83 additions & 0 deletions title_maker_pro/wotd_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import json
import time
import argparse
import logging
import os
from word_generator import WordGenerator
from google.cloud import storage

logger = logging.getLogger(__name__)


def upload_wotd(blob, word_generator):
word = word_generator.generate_word()
if not word:
raise RuntimeError("Error during generation")

blob.upload_from_string(json.dumps({
"word": word.word,
"part_of_speech": word.pos,
"definition": word.definition,
"example_usage": word.example,
"topic": word.topic,
"generated_at_ms": int(1000 * time.time()),
}),
content_type="application/jon"
)


def main(args):
gcloud_credentials = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS")
if not gcloud_credentials:
raise RuntimeError("Expected to set GOOGLE_APPLICATION_CREDENTIALS env var")
# Remove all handlers associated with the root logger object.
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)

lvl = logging.DEBUG if args.verbose else logging.INFO
if args.log_file:
print(f"Logging to {args.log_file}")
logging.basicConfig(
level=lvl, filename=args.log_file, filemode="a", format="%(asctime)s - %(levelname)s - %(message)s",
)
else:
logging.basicConfig(level=lvl)

word_generator = WordGenerator(
device=args.device,
forward_model_path=args.forward_model_path,
inverse_model_path=args.inverse_model_path,
blacklist_path=args.blacklist_path,
quantize=args.quantize,
)

logger.info("Uploading WOTD")
client = storage.Client(project=args.gcloud_project)
bucket = client.get_bucket(args.gcloud_bucket)
blob = bucket.blob(args.gcloud_path)
upload_wotd(blob, word_generator)


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run a wotd bot that uploads a wotd to a specified google bucket")
parser.add_argument(
"--device", help="Force a certain device (cuda / cpu)", type=str,
)
parser.add_argument("--forward-model-path", help="Model path for (Word -> Definition)", type=str, required=True)
parser.add_argument("--inverse-model-path", help="Model path for (Definition -> Word)", type=str, required=True)
parser.add_argument(
"--blacklist-path", help="Blacklist path for word generation", type=str, required=True,
)
parser.add_argument("--quantize", help="Perform quantization for models", action="store_true")
parser.add_argument("--log-file", type=str, help="Log to this file")
parser.add_argument("--verbose", action="store_true", help="Verbose logging")
parser.add_argument("--gcloud-project", type=str, required=True)
parser.add_argument("--gcloud-bucket", type=str, required=True)
parser.add_argument("--gcloud-path", type=str, default="wotd.json")
args = parser.parse_args()

try:
main(args)
except Exception:
logger.exception("Uncaught error")
raise

0 comments on commit 965405f

Please sign in to comment.