Browse Source

Getting app to run on new server under gunicorn

Tyler Hallada 6 years ago
parent
commit
e687c2ad61
5 changed files with 33 additions and 36 deletions
  1. 1 1
      app.py
  2. 26 26
      generate_poem.py
  3. 4 0
      nlp.py
  4. 0 8
      nlp.wsgi
  5. 2 1
      requirements.txt

+ 1 - 1
app.py

@@ -10,7 +10,7 @@ def home():
10 10
     return redirect('http://git.hallada.net/nlp/')
11 11
 
12 12
 
13
-@app.route("/buzzfeed-haiku-generator/")
13
+@app.route("/nlp/buzzfeed_haiku_generator/")
14 14
 def buzzfeed_haiku_generator():
15 15
     haiku = generator.generate_haiku()
16 16
     return render_template('buzzfeed-haiku-generator.html', haiku=haiku)

+ 26 - 26
generate_poem.py

@@ -33,31 +33,31 @@ class PoemGenerator():
33 33
         self.words = []
34 34
         self.all_words = []
35 35
         self.inflect_engine = inflect.engine()
36
-        #  with open('/var/www/buzzfeed-haiku-generator/buzzfeed_facebook_statuses.csv', newline='', encoding='utf-8') as statuses:
37
-            #  reader = csv.reader(statuses, delimiter=',')
38
-            #  for row in reader:
39
-                #  if 'via buzzfeed ' not in row[1].lower():  # only English
40
-                    #  # split title into a list of words and punctuation
41
-                    #  title = self.spaces_and_punctuation.findall(row[2])
42
-                    #  # spell out digits into ordinal words for syllable counting
43
-                    #  title = [string.capwords(
44
-                             #  self.inflect_engine.number_to_words(int(word)))
45
-                             #  if word.isdigit() else word for word in title]
46
-                    #  self.sents.append(title)
47
-                    #  self.words.extend(title)
48
-                    #  # all_words only contains words, no punctuation
49
-                    #  self.all_words.extend([word for word in title
50
-                                           #  if not
51
-                                           #  self.only_punctuation.match(word)])
52
-        with codecs.open('trump.txt', 'r', 'utf-8') as corpus:
53
-            text = corpus.read()
54
-            sents = nltk.tokenize.sent_tokenize(text)
55
-            words = nltk.tokenize.word_tokenize(text)
56
-            self.sents.extend(sents)
57
-            self.words.extend(words)
58
-            self.all_words.extend([word for word in words
59
-                                   if not
60
-                                   self.only_punctuation.match(word)])
36
+        with open('buzzfeed_facebook_statuses.csv', newline='', encoding='utf-8') as statuses:
37
+            reader = csv.reader(statuses, delimiter=',')
38
+            for row in reader:
39
+                if 'via buzzfeed ' not in row[1].lower():  # only English
40
+                    # split title into a list of words and punctuation
41
+                    title = self.spaces_and_punctuation.findall(row[2])
42
+                    # spell out digits into ordinal words for syllable counting
43
+                    title = [string.capwords(
44
+                             self.inflect_engine.number_to_words(int(word)))
45
+                             if word.isdigit() else word for word in title]
46
+                    self.sents.append(title)
47
+                    self.words.extend(title)
48
+                    # all_words only contains words, no punctuation
49
+                    self.all_words.extend([word for word in title
50
+                                           if not
51
+                                           self.only_punctuation.match(word)])
52
+        #  with codecs.open('trump.txt', 'r', 'utf-8') as corpus:
53
+            #  text = corpus.read()
54
+            #  sents = nltk.tokenize.sent_tokenize(text)
55
+            #  words = nltk.tokenize.word_tokenize(text)
56
+            #  self.sents.extend(sents)
57
+            #  self.words.extend(words)
58
+            #  self.all_words.extend([word for word in words
59
+                                   #  if not
60
+                                   #  self.only_punctuation.match(word)])
61 61
         self.bigrams = list(nltk.bigrams(self.words))
62 62
         self.cfd = nltk.ConditionalFreqDist(self.bigrams)
63 63
         #self.parser = Parser()
@@ -142,5 +142,5 @@ if __name__ == '__main__':
142 142
     generator = PoemGenerator()
143 143
     #generator.generate_poem()
144 144
     haiku = generator.generate_haiku()
145
-    print haiku
145
+    print(haiku)
146 146
     #generator.generate_endless_poem(None)

+ 4 - 0
nlp.py

@@ -0,0 +1,4 @@
1
+from app import app
2
+
3
+if __name__ == '__main__':
4
+    app.run()

+ 0 - 8
nlp.wsgi

@@ -1,8 +0,0 @@
1
-import os
2
-import sys
3
-sys.path.append('/var/www/nlp')
4
-
5
-import logging
6
-logging.basicConfig(stream=sys.stderr)
7
-
8
-from app import app as application

+ 2 - 1
requirements.txt

@@ -1,11 +1,12 @@
1 1
 click==6.7
2 2
 Flask==0.12.2
3
+gunicorn==19.7.1
3 4
 inflect==0.2.5
4 5
 itsdangerous==0.24
5 6
 Jinja2==2.9.6
6 7
 MarkupSafe==1.0
7 8
 nltk==3.2.4
8
-pyStatParser==0.0.1
9
+# pyStatParser==0.0.1 manually install from git repo (python2 only)
9 10
 six==1.10.0
10 11
 tqdm==4.14.0
11 12
 Werkzeug==0.12.2