-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
99 lines (82 loc) · 2.57 KB
/
Copy pathapi.py
File metadata and controls
99 lines (82 loc) · 2.57 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from flask import Flask, request, jsonify
import json
from api_helper import predict
from flask_swagger_ui import get_swaggerui_blueprint
from flask_cors import CORS, cross_origin
# import pandas as pd
app = Flask(__name__)
CORS(app)
SWAGGER_URL = '/docs'
API_URL = '/static/swagger.json'
SWAGGER_BLUEPRINT = get_swaggerui_blueprint(
SWAGGER_URL,
API_URL,
config={
'app_name': 'Sentiment Analysis API'
}
)
app.register_blueprint(SWAGGER_BLUEPRINT, url_prefix=SWAGGER_URL)
@app.route("/predict", methods=["POST", "GET"])
def predict_file():
if request.method == "POST":
file = request.files["file"]
algo = request.form["algo"]
data = predict(file, algo)
return jsonify(data)
return "Send some data bitch"
@app.route("/fake")
def fake():
return jsonify(
[
{
"confidence": 0.9884693026542664,
"index": 0,
"lable": "+",
"text": "i bought the product last week and i have to admit i liked the product. This product has amazing features",
},
{
"confidence": 0.9992623925209045,
"index": 1,
"lable": "+",
"text": "i am amazed with the quality of the product. giving five stars.",
},
{
"confidence": 0.642754077911377,
"index": 2,
"lable": "-",
"text": "it doesnot works for me at all......this product is realy a shit.",
},
{
"confidence": 0.7229446172714233,
"index": 3,
"lable": "-",
"text": "i donot like the product.",
},
{
"confidence": 0.6997010707855225,
"index": 4,
"lable": "-",
"text": "Initially i liked the phone but after some time it started lagging and problem of battery drainage started.",
},
{
"confidence": 0.9998747110366821,
"index": 5,
"lable": "+",
"text": "the product is amazing i just loved it .",
},
{
"index": 6,
"meter": -65,
"most_negetive_index": 2,
"most_positive_index": 5,
"n_negetive": 3,
"n_positive": 3,
"total_reviews": 6,
},
]
)
@app.route("/")
def home():
return "0"
if __name__ == "__main__":
app.run(debug=True)