Update app.py
Browse files
app.py
CHANGED
|
@@ -5,10 +5,6 @@ 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 |
-
|
| 11 |
-
app = Flask(__name__)
|
| 12 |
|
| 13 |
|
| 14 |
# load dataset
|
|
@@ -29,37 +25,19 @@ model = keras.models.load_model('model')
|
|
| 29 |
# parameters
|
| 30 |
max_len = 20
|
| 31 |
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
# Retrieve the input text from the request
|
| 36 |
-
question = request.json['text']
|
| 37 |
|
| 38 |
-
result = model.predict(keras.preprocessing.sequence.pad_sequences(tokenizer.texts_to_sequences([question]),
|
| 39 |
-
truncating='post', maxlen=max_len))
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
tag = lbl_encoder.inverse_transform([np.argmax(result)])
|
| 42 |
|
| 43 |
for i in data['intents']:
|
| 44 |
if i['tag'] == tag:
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
# Return the answer as a JSON response
|
| 48 |
-
response = {'answer': answer}
|
| 49 |
-
return jsonify(response)
|
| 50 |
-
|
| 51 |
-
if __name__ == '__main__':
|
| 52 |
-
app.run()
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
question = st.text_area('....اسأل سؤال')
|
| 56 |
-
|
| 57 |
-
result = model.predict(keras.preprocessing.sequence.pad_sequences(tokenizer.texts_to_sequences([question]),
|
| 58 |
-
truncating='post', maxlen=max_len))
|
| 59 |
-
|
| 60 |
-
tag = lbl_encoder.inverse_transform([np.argmax(result)])
|
| 61 |
-
|
| 62 |
-
for i in data['intents']:
|
| 63 |
-
if i['tag'] == tag:
|
| 64 |
-
out = np.random.choice(i['responses'])
|
| 65 |
-
st.write(out)
|
|
|
|
| 5 |
import streamlit as st
|
| 6 |
from tensorflow import keras
|
| 7 |
from sklearn.preprocessing import LabelEncoder
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
# load dataset
|
|
|
|
| 25 |
# parameters
|
| 26 |
max_len = 20
|
| 27 |
|
| 28 |
+
question = st.text_area('....اسأل سؤال')
|
| 29 |
|
| 30 |
+
if question == '':
|
| 31 |
+
st.write('')
|
|
|
|
|
|
|
| 32 |
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
else:
|
| 35 |
+
result = model.predict(keras.preprocessing.sequence.pad_sequences(tokenizer.texts_to_sequences([question]),
|
| 36 |
+
truncating='post', maxlen=max_len))
|
| 37 |
+
|
| 38 |
tag = lbl_encoder.inverse_transform([np.argmax(result)])
|
| 39 |
|
| 40 |
for i in data['intents']:
|
| 41 |
if i['tag'] == tag:
|
| 42 |
+
out = np.random.choice(i['responses'])
|
| 43 |
+
st.write(out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|