Spaces:
Build error
Build error
Commit ·
651f27d
1
Parent(s): 6df6502
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pickle
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from tensorflow.keras.layers import TextVectorization
|
| 4 |
+
|
| 5 |
+
def sentiment_pred(text):
|
| 6 |
+
load_vectorizer = pickle.load(open("tv_layer.pkl", "rb"))
|
| 7 |
+
new_vectorizer = TextVectorization.from_config(load_vectorizer['config'])
|
| 8 |
+
# You have to call `adapt` with some dummy data (BUG in Keras)
|
| 9 |
+
new_vectorizer.adapt(tf.data.Dataset.from_tensor_slices(["xyz"])) #some argues that it is not necessary
|
| 10 |
+
new_vectorizer.set_weights(load_vectorizer['weights'])
|
| 11 |
+
|
| 12 |
+
vectorized_text = new_vectorizer([text])
|
| 13 |
+
load_model = tf.keras.models.load_model('ar_sentiment_2.h5')
|
| 14 |
+
result = load_model.predict([vectorized_text])
|
| 15 |
+
x = np.argmax(result[0])+1
|
| 16 |
+
return x
|
| 17 |
+
|
| 18 |
+
interface = gr.Interface(fn=sentiment_pred,
|
| 19 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder='enter your text'),
|
| 20 |
+
outputs=["text"])
|
| 21 |
+
interface.launch()
|