Spaces:
Build error
Build error
Commit ·
07ab9cf
1
Parent(s): 41cd75b
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,20 +3,24 @@ import gradio as gr
|
|
| 3 |
import tensorflow as tf
|
| 4 |
from tensorflow.keras.layers import TextVectorization
|
| 5 |
|
| 6 |
-
def
|
| 7 |
-
load_vectorizer = pickle.load(open("
|
| 8 |
new_vectorizer = TextVectorization.from_config(load_vectorizer['config'])
|
| 9 |
# You have to call `adapt` with some dummy data (BUG in Keras)
|
| 10 |
new_vectorizer.adapt(tf.data.Dataset.from_tensor_slices(["xyz"])) #some argues that it is not necessary
|
| 11 |
new_vectorizer.set_weights(load_vectorizer['weights'])
|
| 12 |
|
| 13 |
vectorized_text = new_vectorizer([text])
|
| 14 |
-
load_model = tf.keras.models.load_model('.
|
| 15 |
result = load_model.predict([vectorized_text])
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
interface = gr.Interface(fn=
|
| 20 |
inputs=gr.inputs.Textbox(lines=2, placeholder='enter your text'),
|
| 21 |
outputs=["text"])
|
| 22 |
interface.launch()
|
|
|
|
| 3 |
import tensorflow as tf
|
| 4 |
from tensorflow.keras.layers import TextVectorization
|
| 5 |
|
| 6 |
+
def sentiment_pred2(text):
|
| 7 |
+
load_vectorizer = pickle.load(open("tv_layer.pkl", "rb"))
|
| 8 |
new_vectorizer = TextVectorization.from_config(load_vectorizer['config'])
|
| 9 |
# You have to call `adapt` with some dummy data (BUG in Keras)
|
| 10 |
new_vectorizer.adapt(tf.data.Dataset.from_tensor_slices(["xyz"])) #some argues that it is not necessary
|
| 11 |
new_vectorizer.set_weights(load_vectorizer['weights'])
|
| 12 |
|
| 13 |
vectorized_text = new_vectorizer([text])
|
| 14 |
+
load_model = tf.keras.models.load_model('ar_sentiment_15_ep.h5')
|
| 15 |
result = load_model.predict([vectorized_text])
|
| 16 |
+
pred = np.argmax(result[0])+1
|
| 17 |
+
labels = ["نص يعبر عن الاستياء","نص يعبر عن الحياد","نص يعبر عن الثناء"]
|
| 18 |
+
print(pred)
|
| 19 |
+
print(np.argmax(pred))
|
| 20 |
+
print(labels[np.argmax(pred)-1])
|
| 21 |
+
return (labels[np.argmax(pred)-1])
|
| 22 |
|
| 23 |
+
interface = gr.Interface(fn=sentiment_pred2,
|
| 24 |
inputs=gr.inputs.Textbox(lines=2, placeholder='enter your text'),
|
| 25 |
outputs=["text"])
|
| 26 |
interface.launch()
|