-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
46 lines (36 loc) · 1.5 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from flask import Flask, request, send_file, render_template
import csv
import pandas as pd
import comparison
application = Flask(__name__)
@application.route('/', methods=['GET'])
def home():
return render_template('index.html')
@application.route('/compare', methods=['POST'])
def compare():
url1 = request.form['url1']
url2 = request.form['url2']
semantic_similarity, ngram_similarity = comparison.compare(url1, url2)
return f'Semantic similarity: {semantic_similarity}, N-gram similarity: {ngram_similarity}'
@application.route('/upload', methods=['POST'])
def upload_file():
if request.method == 'POST':
f = request.files['csvfile']
# Load csv file into pandas dataframe
data = pd.read_csv(f)
# Initialize result list
result = []
# Iterate over each row of dataframe
for index, row in data.iterrows():
url1 = row[0]
url2 = row[1]
semantic_similarity, ngram_similarity = comparison.compare(url1, url2)
result.append([url1, url2, semantic_similarity, ngram_similarity])
# Convert result into pandas dataframe and save it to csv file
result_df = pd.DataFrame(result, columns=['URL1', 'URL2', 'Semantic Similarity', 'N-gram Similarity'])
result_file = 'result.csv'
result_df.to_csv(result_file, index=False)
# Send the result csv file
return send_file(result_file, as_attachment=True)
if __name__ == '__main__':
application.run(debug=True)