Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -402,26 +402,26 @@ def predict(text):
|
|
402 |
word_list = text_to_wordlist(text)
|
403 |
sequences = tokenizer.texts_to_sequences([word_list])
|
404 |
sequences_input = list(itertools.chain(*sequences))
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
409 |
pred = Modell.predict(input_a, batch_size=None, verbose=0, steps=None)
|
410 |
#print(pred)
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
for i in range(len(sequences_input) - window_size + 1):
|
416 |
-
window_input = sequences_input[i : i + window_size]
|
417 |
-
#print(window_input)
|
418 |
-
input_a = np.asarray([window_input])
|
419 |
-
pred = Modell.predict(input_a, batch_size=None, verbose=0, steps=None)
|
420 |
-
#print(pred)
|
421 |
-
predictions.append(pred)
|
422 |
-
accumulated_pred = np.sum(predictions, axis=0)
|
423 |
-
predicted_class = np.argmax(np.sum(accumulated_pred, axis=0))
|
424 |
-
#print(labels[predicted_class])
|
425 |
|
426 |
return labels[predicted_class]
|
427 |
input_text = gr.inputs.Textbox(label="Enter a sentence")
|
|
|
402 |
word_list = text_to_wordlist(text)
|
403 |
sequences = tokenizer.texts_to_sequences([word_list])
|
404 |
sequences_input = list(itertools.chain(*sequences))
|
405 |
+
if len(sequences_input) <= window_size:
|
406 |
+
sequences_input = pad_sequences([sequences_input], value=0, padding="post", maxlen=window_size).tolist()
|
407 |
+
#print(sequences_input)
|
408 |
+
input_a = np.asarray(sequences_input)
|
409 |
+
pred = Modell.predict(input_a, batch_size=None, verbose=0, steps=None)
|
410 |
+
#print(pred)
|
411 |
+
predicted_class = np.argmax(pred)
|
412 |
+
#print(labels[predicted_class])
|
413 |
+
else:
|
414 |
+
predictions = []
|
415 |
+
for i in range(len(sequences_input) - window_size + 1):
|
416 |
+
window_input = sequences_input[i : i + window_size]
|
417 |
+
#print(window_input)
|
418 |
+
input_a = np.asarray([window_input])
|
419 |
pred = Modell.predict(input_a, batch_size=None, verbose=0, steps=None)
|
420 |
#print(pred)
|
421 |
+
predictions.append(pred)
|
422 |
+
accumulated_pred = np.sum(predictions, axis=0)
|
423 |
+
predicted_class = np.argmax(np.sum(accumulated_pred, axis=0))
|
424 |
+
#print(labels[predicted_class])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
|
426 |
return labels[predicted_class]
|
427 |
input_text = gr.inputs.Textbox(label="Enter a sentence")
|