-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentanalysis.py
32 lines (27 loc) · 919 Bytes
/
sentanalysis.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
# Description: Sentiment Analysis with Coherence
from flask import Flask, render_template, request, jsonify
import cohere
from cohere.classify import Example
from config import API_KEY
import os
app = Flask(__name__)
co = cohere.Client(API_KEY)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
data = request.get_json()
feedback = data['feedback']
inputs = [feedback]
response = co.classify(
# model='de75337f-360c-41a7-a07a-ddcc026f6a2e-ft',
model='edf20e4f-1466-4000-a319-4f008c3d7b7f-ft',
inputs=inputs,
# examples=examples,
)
for classification in response.classifications:
prediction = classification.prediction
break
return jsonify({'prediction': prediction})
return render_template('index.html')
if __name__ == '__main__':
app.run()