-
Notifications
You must be signed in to change notification settings - Fork 13
/
App_nlu.py
32 lines (28 loc) · 1007 Bytes
/
App_nlu.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
from flask import session,flash
import pandas as pd
import numpy as np
from flask import Response
import os
from flask import Flask, render_template, request, redirect, url_for, send_from_directory,jsonify
import tempfile
import simplejson as j
from rasa_nlu.training_data import load_data
from rasa_nlu.config import RasaNLUModelConfig
from rasa_nlu.model import Trainer
from rasa_nlu.model import Metadata, Interpreter
import json
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
interpreter = Interpreter.load('./models/nlu/default/restaurantnlu')
@app.route('/nlu_parsing', methods=['POST'])
def transform():
if request.headers['Content-Type'] == 'application/json':
query = request.json.get("utterance")
results=interpreter.parse(query)
js = json.dumps(results)
resp = Response(js, status=200, mimetype='application/json')
return resp
if __name__ == '__main__':
app.run(debug=True)