Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
def greet(name):
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
import numpy as np
|
| 6 |
+
import pickle
|
| 7 |
+
|
| 8 |
+
# Load model, including its weights and the optimizer
|
| 9 |
+
model = tf.keras.models.load_model('core4.h5')
|
| 10 |
+
|
| 11 |
+
# load tokenizer
|
| 12 |
+
with open('tokenizer.pickle', 'rb') as handle:
|
| 13 |
+
tokenize = pickle.load(handle)
|
| 14 |
+
|
| 15 |
+
text_labels = ['How to apply', 'how much can I get', 'who can apply']
|
| 16 |
+
|
| 17 |
+
# model.summary() # model architecture
|
| 18 |
+
|
| 19 |
def greet(name):
|
| 20 |
+
|
| 21 |
+
tokenizedText = tokenize.texts_to_matrix([string])
|
| 22 |
+
prediction = model.predict(np.array([tokenizedText[0]]))
|
| 23 |
+
predicted_label = text_labels[np.argmax(prediction)]
|
| 24 |
+
|
| 25 |
+
print(prediction[0][np.argmax(prediction)])
|
| 26 |
+
print("Predicted label: " + predicted_label + "\n")
|
| 27 |
+
|
| 28 |
+
return predicted_label
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
#One testing case
|
| 32 |
+
|
| 33 |
|
| 34 |
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 35 |
iface.launch()
|