Spaces:
Runtime error
Runtime error
bhavyapandya
commited on
Commit
•
79af434
1
Parent(s):
9fc52c9
Upload 4 files
Browse files- app.py +35 -0
- model.h5 +3 -0
- requirements.txt +0 -0
- tokenizer.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from tensorflow import keras
|
4 |
+
import tensorflow as tf
|
5 |
+
import pickle
|
6 |
+
from tensorflow.keras.models import load_model
|
7 |
+
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
8 |
+
|
9 |
+
pickle_open = open("tokenizer.pkl","rb")
|
10 |
+
tokenizer = pickle.load(pickle_open)
|
11 |
+
model = load_model("model.h5")
|
12 |
+
pickle_open.close()
|
13 |
+
|
14 |
+
def predict(t):
|
15 |
+
example = tokenizer.texts_to_sequences([t])
|
16 |
+
example = pad_sequences(example, maxlen=2)
|
17 |
+
prediction = model.predict(np.array(example))
|
18 |
+
predictions = []
|
19 |
+
sorted_ = np.sort(prediction[0])[::-1]
|
20 |
+
|
21 |
+
for i in sorted_[:5]:
|
22 |
+
predictions.append(np.where(prediction[0] == i)[0])
|
23 |
+
predicted_words = []
|
24 |
+
reverse_word_map = dict(map(reversed, tokenizer.word_index.items()))
|
25 |
+
for i in predictions:
|
26 |
+
predicted_words.append(reverse_word_map[i[0]])
|
27 |
+
return predicted_words
|
28 |
+
|
29 |
+
input_text = gr.inputs.Textbox(lines=1, placeholder="Enter sentence or word here...")
|
30 |
+
output_text = gr.outputs.Textbox()
|
31 |
+
|
32 |
+
title = "Next Word Prediction"
|
33 |
+
description = "Enter some text or sentence or word and get the next 5 possible autocompletion words"
|
34 |
+
|
35 |
+
gr.Interface(fn=predict, inputs=input_text, outputs=output_text, title=title, description=description).launch()
|
model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3a4d272b3473e658b28c418a7147e9b155f8e3658c24c77aef18b6747f407d0c
|
3 |
+
size 14168072
|
requirements.txt
ADDED
Binary file (3.69 kB). View file
|
|
tokenizer.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:da96e37ac2b81afc0774a55ccd5e772e79e8dfe57f0104d0757c36084ac71d98
|
3 |
+
size 2929187
|