Skip to content

Commit

Permalink
add wiki api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Enochen committed May 28, 2019
1 parent 40b9823 commit 6504967
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
6 changes: 5 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
app = Flask(__name__)
app.config['CORS_HEADERS'] = 'Content-Type'

cors = CORS(app, resources={r"/api/mash": {"origins": "*"}})
cors = CORS(app, resources={r"/api/mash": {"origins": "*"},r"/api/wiki": {"origins": "*"}})

@app.route('/',methods=['GET'])
def index():
return render_template("index.html")

@app.route('/api/wiki', methods=['POST'])
def wiki():
return jsonify(result=mash.random_wiki())

@app.route('/api/mash', methods=['POST'])
def madlibs():
o = request.get_json(force=True)['original']
Expand Down
33 changes: 23 additions & 10 deletions mash.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __random_summary(min, max):
break
except:
return __random_summary(min, max)
return result
return result.decode('utf-8')


def __search(list, token):
Expand Down Expand Up @@ -64,24 +64,37 @@ def __get_similarity(doc1, doc2, doc3):
print("Similarity 1-2-3:", s12 + s23)
print()
return s12 + s23;

def __diff(doc1, doc2):
d = 0
print(len(doc1), 'vs', len(doc2))
for i in range(len(doc1)):
if(doc1[i].tag_ != doc2[i].tag_):
d += 1
return d


def random_wiki():
return __random_summary(0, 1500)

def mashup(**kwargs):
print("starting")
original = __random_summary(500, 1000).decode('utf-8')
#original = __random_summary(0, 1500).decode('utf-8')
print("finished fetching o: length =", len(original))
#modifier = __random_summary(len(original)-100, len(original)+200).decode('utf-8')
modifier = __random_summary(len(original), 1500).decode('utf-8')
print("finished fetching m: length =", len(modifier))
original = ''
modifier = ''
craziness = 100

if 'original' in kwargs and not kwargs['original'] == '':
original = kwargs['original']
else:
original = __random_summary(500, 1000)
#original = __random_summary(0, 1500)
print("finished fetching o: length =", len(original))

if 'modifier' in kwargs and not kwargs['modifier'] == '':
modifier = kwargs['modifier']
else:
#modifier = __random_summary(len(original)-100, len(original)+200)
modifier = __random_summary(len(original), 1500)
print("finished fetching m: length =", len(modifier))

if 'craziness' in kwargs and not kwargs['craziness'] == '':
craziness = kwargs['craziness']
Expand All @@ -105,9 +118,9 @@ def mashup(**kwargs):
print()

sentences = []
for i in range(10):
for i in range(100):
sentences.append(__gen_sen(doc_original, words, craziness))
best = min(sentences, key=lambda x: __get_similarity(x, doc_original, doc_modifier))
best = max(sentences, key=lambda x: doc_original.similarity(x))
return (original, modifier, best.text)

#print(mashup()[2].encode('utf-8'))
16 changes: 16 additions & 0 deletions template/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html>
<head>
<title>Half Bot Half Brain</title>
</head>
<body>
<div>
<center>
<h1>Half Bot Half Brain API</h1>
<p>Created by Austin George, Enoch Chen, Gloria Moon, Aaron Lee for TeenhacksLI 2019</p>
<p>This site uses Natural Language Processing to alter text.</p>
<br/>
<h2>Documentation: [to be implemented]</h2>
</center>
</div>
</body>
</html>

0 comments on commit 6504967

Please sign in to comment.