DHRUV SHEKHAWAT commited on
Commit
35294b9
·
1 Parent(s): 49f3a23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -44,8 +44,8 @@ st.subheader("Next Word Prediction AI Model by Webraft-AI")
44
  #Picking what NLP task you want to do
45
  option = st.selectbox('Model',('1')) #option is stored in this variable
46
  #Textbox for text user is entering
47
- st.subheader("Enter the text you'd like to analyze.")
48
- text = st.text_input('Enter word: ') #text is stored in this variable
49
 
50
  if option == '1':
51
  with open("data2.txt","r") as f:
@@ -81,30 +81,31 @@ if option == '1':
81
  chatbot.compile(optimizer="adam", loss="sparse_categorical_crossentropy")
82
 
83
  for i in range(1):
84
- other_text1 = text
85
  other_text1 = other_text1.lower()
86
  other_words1 = other_text1.split()
87
  other_num1 = [word_to_num[word] for word in other_words1]
88
  given_X1 = other_num1
89
  input_sequence1 = pad_sequences([given_X1], maxlen=max_len, padding='post')
90
  output_sentence = other_text1+""
91
- for _ in range(15):
92
  predicted_token = np.argmax(chatbot.predict(input_sequence1), axis=-1)
93
  predicted_token = predicted_token.item()
94
  out = num_to_word[predicted_token]
95
- if out == ".":
96
- break
97
 
98
  output_sentence += " " + out
 
 
99
  given_X1 = given_X1[1:]
100
  given_X1.append(predicted_token)
101
  input_sequence1 = pad_sequences([given_X1], maxlen=max_len, padding='post')
102
 
103
- out = output_sentence
104
 
105
 
106
  else:
107
- out = "Wrong Model"
108
 
109
  st.write("Predicted Text: ")
110
- st.write(out)
 
44
  #Picking what NLP task you want to do
45
  option = st.selectbox('Model',('1')) #option is stored in this variable
46
  #Textbox for text user is entering
47
+ st.subheader("Enter a word from which a sentence would be predicted")
48
+ text2 = st.text_input('Enter word: ') #text is stored in this variable
49
 
50
  if option == '1':
51
  with open("data2.txt","r") as f:
 
81
  chatbot.compile(optimizer="adam", loss="sparse_categorical_crossentropy")
82
 
83
  for i in range(1):
84
+ other_text1 = text2
85
  other_text1 = other_text1.lower()
86
  other_words1 = other_text1.split()
87
  other_num1 = [word_to_num[word] for word in other_words1]
88
  given_X1 = other_num1
89
  input_sequence1 = pad_sequences([given_X1], maxlen=max_len, padding='post')
90
  output_sentence = other_text1+""
91
+ for _ in range(1):
92
  predicted_token = np.argmax(chatbot.predict(input_sequence1), axis=-1)
93
  predicted_token = predicted_token.item()
94
  out = num_to_word[predicted_token]
95
+
 
96
 
97
  output_sentence += " " + out
98
+ if out == ".":
99
+ break
100
  given_X1 = given_X1[1:]
101
  given_X1.append(predicted_token)
102
  input_sequence1 = pad_sequences([given_X1], maxlen=max_len, padding='post')
103
 
104
+ out2 = output_sentence
105
 
106
 
107
  else:
108
+ out2 = "Wrong Model"
109
 
110
  st.write("Predicted Text: ")
111
+ st.write(out2)