Wootang01 bhavyapandya commited on
Commit
03aea74
0 Parent(s):

Duplicate from bhavyapandya/Next-Word-Prediction

Browse files

Co-authored-by: Bhavya Pandya <[email protected]>

Files changed (6) hide show
  1. .gitattributes +34 -0
  2. README.md +14 -0
  3. app.py +35 -0
  4. model.h5 +3 -0
  5. requirements.txt +0 -0
  6. tokenizer.pkl +3 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Next Word Prediction
3
+ emoji: 🚀
4
+ colorFrom: pink
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 3.32.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ duplicated_from: bhavyapandya/Next-Word-Prediction
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
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(text):
15
+ example = tokenizer.texts_to_sequences([text])
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