Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -350,17 +350,44 @@ windows_size = 10
|
|
350 |
with open('model_google.pkl', 'rb') as f:
|
351 |
Mode = pickle.load(f)
|
352 |
|
353 |
-
def Test_model(text, Model):
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
#print(pred)
|
361 |
-
predicted_class = np.argmax(pred)
|
362 |
#print(labels[predicted_class])
|
363 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
364 |
|
365 |
|
366 |
import gradio as gr
|
@@ -375,11 +402,27 @@ def predict(text):
|
|
375 |
word_list = text_to_wordlist(text)
|
376 |
sequences = tokenizer.texts_to_sequences([word_list])
|
377 |
sequences_input = list(itertools.chain(*sequences))
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
383 |
return labels[predicted_class]
|
384 |
input_text = gr.inputs.Textbox(label="Enter a sentence")
|
385 |
output_text = gr.outputs.Textbox(label="Predicted label")
|
|
|
350 |
with open('model_google.pkl', 'rb') as f:
|
351 |
Mode = pickle.load(f)
|
352 |
|
353 |
+
#def Test_model(text, Model):
|
354 |
+
# word_list = text_to_wordlist(text)
|
355 |
+
# sequences = tokenizer.texts_to_sequences([word_list])
|
356 |
+
# sequences_input = list(itertools.chain(*sequences))
|
357 |
+
# sequences_input = pad_sequences([sequences_input], value=0, padding="post", maxlen=windows_size).tolist()
|
358 |
+
# input_a = np.asarray(sequences_input)
|
359 |
+
# pred = Model.predict(input_a, batch_size=None, verbose=0, steps=None)
|
360 |
#print(pred)
|
361 |
+
#predicted_class = np.argmax(pred)
|
362 |
#print(labels[predicted_class])
|
363 |
|
364 |
+
def Test_model(text, model, window_size=10):
|
365 |
+
#print(text)
|
366 |
+
word_list = text_to_wordlist(text)
|
367 |
+
#print(word_list)
|
368 |
+
sequences = tokenizer.texts_to_sequences([word_list])
|
369 |
+
sequences_input = list(itertools.chain(*sequences))
|
370 |
+
|
371 |
+
if len(sequences_input) <= window_size:
|
372 |
+
sequences_input = pad_sequences([sequences_input], value=0, padding="post", maxlen=window_size).tolist()
|
373 |
+
#print(sequences_input)
|
374 |
+
input_a = np.asarray(sequences_input)
|
375 |
+
pred = Modell.predict(input_a, batch_size=None, verbose=0, steps=None)
|
376 |
+
#print(pred)
|
377 |
+
predicted_class = np.argmax(pred)
|
378 |
+
#print(labels[predicted_class])
|
379 |
+
else:
|
380 |
+
predictions = []
|
381 |
+
for i in range(len(sequences_input) - window_size + 1):
|
382 |
+
window_input = sequences_input[i : i + window_size]
|
383 |
+
#print(window_input)
|
384 |
+
input_a = np.asarray([window_input])
|
385 |
+
pred = Modell.predict(input_a, batch_size=None, verbose=0, steps=None)
|
386 |
+
#print(pred)
|
387 |
+
predictions.append(pred)
|
388 |
+
accumulated_pred = np.sum(predictions, axis=0)
|
389 |
+
predicted_class = np.argmax(np.sum(accumulated_pred, axis=0))
|
390 |
+
#print(labels[predicted_class])
|
391 |
|
392 |
|
393 |
import gradio as gr
|
|
|
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")
|
428 |
output_text = gr.outputs.Textbox(label="Predicted label")
|