Skip to content

Commit

Permalink
Deployment working
Browse files Browse the repository at this point in the history
  • Loading branch information
WillKoehrsen committed Nov 17, 2018
1 parent fdbd77b commit aae8c60
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 590 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,2 @@
{
}
Binary file added deployment/images/random.PNG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 13 additions & 11 deletions deployment/run_keras_server.py
Expand Up @@ -11,20 +11,21 @@


class ReusableForm(Form):
"""User entry form for entering specifics"""
"""User entry form for entering specifics for generation"""
# Starting seed
seed = TextField("Enter a seed string or 'random':", validators=[
validators.InputRequired(message='A seed string is required')])

# Diversity of predictions
diversity = DecimalField('Enter diversity:', default=0.8,
validators=[validators.InputRequired(),
validators.NumberRange(min=0.5, max=5.0,
message='Diversity must be between 0.5 and 5.')])

# Number of words
words = IntegerField('Enter number of words to generate:',
default=50, validators=[validators.InputRequired(),
validators.NumberRange(min=10, max=100, message='Number of words must be between 10 and 100')])
# Submit button
submit = SubmitField("Send")
submit = SubmitField("Enter")


def load_keras_model():
Expand All @@ -39,7 +40,7 @@ def load_keras_model():
# Home page
@app.route("/", methods=['GET', 'POST'])
def home():
"""Home page of app"""
"""Home page of app with form"""
# Create form
form = ReusableForm(request.form)

Expand All @@ -51,18 +52,19 @@ def home():
words = int(request.form['words'])
# If all vadidations met
if form.validate():
# Generate a random sequence
if seed == 'random':
return generate_output(model=model, graph=graph,
new_words=words, diversity=diversity)
return generate_output(model=model, graph=graph, new_words=words, diversity=diversity)
# Generate starting from a seed sequence
else:
return generate_from_seed(model=model, graph=graph, seed=seed,
new_words=words, diversity=diversity)
# Send template information to home.html
return render_template('home.html', form=form)
return generate_from_seed(model=model, graph=graph, seed=seed, new_words=words, diversity=diversity)
# Send template information to index.html
return render_template('index.html', form=form)


if __name__ == "__main__":
print(("* Loading Keras model and Flask starting server..."
"please wait until server has fully started"))
load_keras_model()
# Run app
app.run(host="0.0.0.0", port=10000)
55 changes: 46 additions & 9 deletions deployment/static/css/main.css
Expand Up @@ -7,8 +7,27 @@ body {


.container {
text-align: center;
background-color: papayawhip;
width: 940px;
margin: 0 auto;
border: 1px double black;
border-width: 4px;
margin-top: 100px;
}

.container::before {
background-image: url('/static/images/script_background.png');
background-size: cover;
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -2;
opacity: 0.4;
}

div.jumbo {
Expand All @@ -19,6 +38,19 @@ body {
border-radius: 6px;
}


h1 {
font-family: none;
color: darkslategray;
display: block;
font-size: 48px;
margin-top: 0.67em;
margin-bottom: 0.67em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}

h2 {
font-size: 3em;
margin-top: 40px;
Expand All @@ -36,23 +68,25 @@ body {
}

form label {
font-size: 1.2em;
font-family: initial;
color: darkblue;
font-size: 26px;
font-weight: bold;
display: block;
padding: 10px 0;
}

form input#seed,
form input#diversity,
form input#words {
form input#seed, form input#diversity, form input#words {
height: 50px;
width: 400px;
background-color: #fafafa;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
border: 1px solid #cccccc;
padding: 5px;
font-size: 1.1em;
font-size: 24px;
margin: 12px;
}

form textarea#message {
Expand All @@ -69,14 +103,17 @@ form textarea#message {
}

form input#submit {
margin: 4px;
display: block;
height:80px;
width:100px;
margin: auto;
display: -webkit-box;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
border:1px solid #d8d8d8;
padding: 10px;
font-weight:bold;
font-size:22px;
text-align: center;
color: #000000;
background-color: #f4f4f4;
Expand Down
Binary file removed deployment/static/images/concert.jpg
Binary file not shown.
Binary file removed deployment/static/images/header.jpg
Binary file not shown.
Binary file removed deployment/static/images/iphone.jpg
Binary file not shown.
Binary file added deployment/static/images/lstm.ico
Binary file not shown.
Binary file removed deployment/static/images/microphone.jpg
Binary file not shown.
Binary file removed deployment/static/images/pencil_sharpener.jpg
Binary file not shown.
Binary file added deployment/static/images/script_background.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed deployment/static/images/writing.jpg
Binary file not shown.
30 changes: 0 additions & 30 deletions deployment/templates/home.html

This file was deleted.

48 changes: 48 additions & 0 deletions deployment/templates/index.html
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>

<head>
<title>RNN Patent Writing</title>
<link rel="stylesheet" href="/static/css/main.css">
<link rel="shortcut icon" href="/static/images/lstm.ico">
</head>

<body>
<div class="container">
<h1>
<center>Writing Novel Patent Abstracts with Recurrent Neural Networks</center>
</h1>


{% block content %}
{% for message in form.seed.errors %}
<div class="flash">{{ message }}</div>
{% endfor %}

{% for message in form.diversity.errors %}
<div class="flash">{{ message }}</div>
{% endfor %}

{% for message in form.words.errors %}
<div class="flash">{{ message }}</div>
{% endfor %}

<form method=post>

{{ form.seed.label }}
{{ form.seed }}

{{ form.diversity.label }}
{{ form.diversity }}

{{ form.words.label }}
{{ form.words }}

{{ form.submit }}
</form>
{% endblock %}

</div>
</body>

</html>
25 changes: 0 additions & 25 deletions deployment/templates/layout.html

This file was deleted.

13 changes: 5 additions & 8 deletions deployment/utils.py
Expand Up @@ -3,9 +3,6 @@
import json
import re

RANDOM_STATE = 50
TRAIN_FRACTION = 0.7


def generate_output(model, graph, seed_length=50,
new_words=50,
Expand Down Expand Up @@ -97,7 +94,7 @@ def generate_output(model, graph, seed_length=50,
a_html = addContent(a_html, header('Actual', color='darkgreen'))
a_html = addContent(a_html, box(remove_spaces(' '.join(a))))

return f'<div><div>{seed_html}</div><div>{gen_html}</div><div>{a_html}</div></div>'
return f'<div style="max-width:80%;margin:auto"><div>{seed_html}</div><div>{gen_html}</div><div>{a_html}</div></div>'


def generate_from_seed(model, graph, seed,
Expand Down Expand Up @@ -149,10 +146,10 @@ def header(text, color='black', gen_text=None):
"""Create an HTML header"""

if gen_text:
raw_html = f'<h1 style="color: {color};font-size:60px"><p><center>' + str(
raw_html = f'<h1 style="margin-top:12px;color: {color};font-size:54px"><p><center>' + str(
text) + '<span style="color: red">' + str(gen_text) + '</center></p></h1>'
else:
raw_html = f'<h1 style="color: {color};font-size:60px"><center>' + str(
raw_html = f'<h1 style="margin-top:12px;color: {color};font-size:54px"><center>' + str(
text) + '</center></h1>'
return raw_html

Expand All @@ -161,11 +158,11 @@ def box(text, gen_text=None):
"""Create an HTML box of text"""

if gen_text:
raw_html = '<div style="border:1px inset black;padding:1em;font-size:32px;margin:auto;max-width:60%"> <p>' + str(
raw_html = '<div style="border:1px inset black;padding:1em;font-size:28px;margin:auto;max-width:60%"> <p>' + str(
text) + '<span style="color: red">' + str(gen_text) + '</p></div>'

else:
raw_html = '<div style="border:1px inset black;padding:1em;font-size: 32px;">' + str(
raw_html = '<div style="border:1px inset black;padding:1em;font-size: 28px;">' + str(
text) + '</div>'
return raw_html

Expand Down

0 comments on commit aae8c60

Please sign in to comment.