-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.py
More file actions
52 lines (42 loc) · 1.6 KB
/
Copy pathserver.py
File metadata and controls
52 lines (42 loc) · 1.6 KB
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
import joblib
import numpy as np
from flask import Flask, render_template, request, redirect, url_for, jsonify, make_response
from flask import jsonify
from utils import Utils
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer, TfidfVectorizer
from sklearn.model_selection import train_test_split
import csv
app = Flask(__name__)
datosPR={}
Uid='nonekey'
key='none'
# routes
@app.route('/')
def Index():
return render_template('index.html')
@app.route('/predict', methods=['GET'])
def predict():
utils = Utils()
return jsonify({'message': 'go to home'})
@app.route('/api', methods=['POST'])
def api():
utils = Utils()
if request.method == 'POST':
wordsU = request.form['words']
Uid = request.form['Uid'] # datos de usuario
key = request.form['key']
if utils.confirmKey(key) == True :
x_test = utils.vectorized_fiting('./in/ropa.csv',utils.textData_cleaning(wordsU))
prediction = model.predict(x_test)
datosPR[wordsU]=prediction[0] #aqui guardan las preguntas y respuestas
archivo = csv.writer(open('in/'+Uid+'.csv',"a", newline=''))#ab
archivo.writerow([wordsU,prediction[0]])
return jsonify({'prediccion': list(prediction)})
else:
return jsonify({'messages': 'debes tener una key de api valida'})
# TODO Sebestian Cristian Jimmy ampliar los request para un post con mensajes
if __name__ == "__main__":
model = joblib.load('./models/0.35873440285204994')
app.run(port=8080, debug=True)