Update app.py
Browse files
app.py
CHANGED
|
@@ -5,9 +5,7 @@ import numpy as np
|
|
| 5 |
import streamlit as st
|
| 6 |
from tensorflow import keras
|
| 7 |
from sklearn.preprocessing import LabelEncoder
|
| 8 |
-
from flask import Flask, request, jsonify
|
| 9 |
|
| 10 |
-
app = Flask(__name__)
|
| 11 |
|
| 12 |
# load dataset
|
| 13 |
with open("intents.json", encoding="utf8") as file:
|
|
@@ -27,28 +25,6 @@ model = keras.models.load_model('model')
|
|
| 27 |
# parameters
|
| 28 |
max_len = 20
|
| 29 |
|
| 30 |
-
|
| 31 |
-
@app.route('/chat', methods=['POST'])
|
| 32 |
-
def translate_text():
|
| 33 |
-
# Retrieve the input text from the request
|
| 34 |
-
question = request.json['text']
|
| 35 |
-
|
| 36 |
-
result = model.predict(keras.preprocessing.sequence.pad_sequences(tokenizer.texts_to_sequences([question]),
|
| 37 |
-
truncating='post', maxlen=max_len))
|
| 38 |
-
|
| 39 |
-
tag = lbl_encoder.inverse_transform([np.argmax(result)])
|
| 40 |
-
|
| 41 |
-
for i in data['intents']:
|
| 42 |
-
if i['tag'] == tag:
|
| 43 |
-
out = np.random.choice(i['responses'])
|
| 44 |
-
response = {'answer': out}
|
| 45 |
-
return jsonify(response)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
if __name__ == '__main__':
|
| 49 |
-
app.run()
|
| 50 |
-
|
| 51 |
-
|
| 52 |
question = st.text_area('....اسأل سؤال')
|
| 53 |
|
| 54 |
if question == '':
|
|
|
|
| 5 |
import streamlit as st
|
| 6 |
from tensorflow import keras
|
| 7 |
from sklearn.preprocessing import LabelEncoder
|
|
|
|
| 8 |
|
|
|
|
| 9 |
|
| 10 |
# load dataset
|
| 11 |
with open("intents.json", encoding="utf8") as file:
|
|
|
|
| 25 |
# parameters
|
| 26 |
max_len = 20
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
question = st.text_area('....اسأل سؤال')
|
| 29 |
|
| 30 |
if question == '':
|