-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
62 lines (51 loc) · 1.98 KB
/
server.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from flask import Flask
from flask import request
from flask_cors import CORS, cross_origin
from codify import Codify
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
PORT = 9000
codify = Codify()
print("Intent Classification and Entity Recognition Model Successfully Loaded....")
@cross_origin()
@app.route('/codify', methods=['POST'])
def codify_request():
"""Given text input, this functions identifies the intent and entities present in it and returns in json format
Example:
Accepts Request like:
{
"text": "insert median values replacing with the null values"
}
Returns:
{
'text': 'insert median values replacing with the null values',
'intent': 'null_imputation',
'entities': [('STATISTICS', 'median')],
'code': [
['from sklearn.impute import SimpleImputer', '# define the imputer', "imputer = SimpleImputer(missing_values=nan, strategy='median')", '# transform the dataset', 'transformed_values = imputer.fit_transform(values)', '# count the number of NaN values in each column', "print('Missing: %d' % isnan(transformed_values).sum())"],
['df.fillna(df.median())', "print('Missing: %d' % isnan(df).sum())"]
]
}
"""
data = request.get_json()
text = data.get('text')
response = codify.codify_engine(text)
print("\n\n")
print(response)
print("\n\n")
return response
@app.route('/', methods=['GET'])
def home():
return "Welcome to Codify Server!"
if __name__ == '__main__':
examples = [
"insert median values replacing with the null values",
"Split dataset into training and test set",
"Duplicate rows in this dataset",
"Construct a bar plot",
"Perform Random Forest Regression",
"Code for all Regression models"
]
print(f"Server running on http://127.0.0.1:{PORT}/")
app.run(host="127.0.0.1", port=PORT)