# -*- coding: utf-8 -*-
"""insult_test.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1wYQD1axz8uxSIT9zxvnrb5AP5zFU8Yxy
"""

from google.colab import drive
drive.mount('/content/drive')

from numpy import array
from keras.preprocessing.text import one_hot
from keras.preprocessing.sequence import pad_sequences
from keras.models import Sequential
from keras.layers.core import Activation, Dropout, Dense
from keras.layers import Flatten, LSTM
from keras.layers import GlobalMaxPooling1D
from keras.models import Model
from keras.layers.embeddings import Embedding
from sklearn.model_selection import train_test_split
from keras.preprocessing.text import Tokenizer
from keras.layers import Input
from keras.layers.merge import Concatenate

import pandas as pd
import numpy as np
import re
import json
import matplotlib.pyplot as plt

def preprocess_text(sen):
    # Remove punctuations and numbers
    sentence = re.sub('[^a-zA-Z]', ' ', sen)

    # Single character removal
    sentence = re.sub(r"\s+[a-zA-Z]\s+", ' ', sentence)

    # Removing multiple spaces
    sentence = re.sub(r'\s+', ' ', sentence)

    return sentence

import pickle
# loading
with open('/content/drive/My Drive/New KS/Toxicity and Insult Detection/Production/Models/insult_tokenizer.pickle', 'rb') as handle:
    tokenizer = pickle.load(handle)

from keras.models import load_model
model = load_model('/content/drive/My Drive/New KS/Toxicity and Insult Detection/Production/Models/insult_model.h5')

def test():
  text = input("Enter sentence ")
  test = []
  test.append(preprocess_text(text))
  test = tokenizer.texts_to_sequences(test)
  maxlen = 200
  test = pad_sequences(test, padding='post', maxlen=maxlen)
  predictions = model.predict(test, verbose=1)
  ins_dict = {"toxic" : float(predictions[0][0]), 
              "severe_toxic" : float(predictions[0][1]),
              "obscene" : float(predictions[0][2]),
              "insult" : float(predictions[0][3])}
  print(json.dumps(ins_dict))

test()
# -*- coding: utf-8 -*-
"""insult_test.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1wYQD1axz8uxSIT9zxvnrb5AP5zFU8Yxy
"""

from google.colab import drive
drive.mount('/content/drive')

from numpy import array
from keras.preprocessing.text import one_hot
from keras.preprocessing.sequence import pad_sequences
from keras.models import Sequential
from keras.layers.core import Activation, Dropout, Dense
from keras.layers import Flatten, LSTM
from keras.layers import GlobalMaxPooling1D
from keras.models import Model
from keras.layers.embeddings import Embedding
from sklearn.model_selection import train_test_split
from keras.preprocessing.text import Tokenizer
from keras.layers import Input
from keras.layers.merge import Concatenate

import pandas as pd
import numpy as np
import re
import json
import matplotlib.pyplot as plt

def preprocess_text(sen):
    # Remove punctuations and numbers
    sentence = re.sub('[^a-zA-Z]', ' ', sen)

    # Single character removal
    sentence = re.sub(r"\s+[a-zA-Z]\s+", ' ', sentence)

    # Removing multiple spaces
    sentence = re.sub(r'\s+', ' ', sentence)

    return sentence

import pickle
# loading
with open('/content/drive/My Drive/New KS/Toxicity and Insult Detection/Production/Models/insult_tokenizer.pickle', 'rb') as handle:
    tokenizer = pickle.load(handle)

from keras.models import load_model
model = load_model('/content/drive/My Drive/New KS/Toxicity and Insult Detection/Production/Models/insult_model.h5')

def test():
  text = input("Enter sentence ")
  test = []
  test.append(preprocess_text(text))
  test = tokenizer.texts_to_sequences(test)
  maxlen = 200
  test = pad_sequences(test, padding='post', maxlen=maxlen)
  predictions = model.predict(test, verbose=1)
  ins_dict = {"toxic" : float(predictions[0][0]), 
              "severe_toxic" : float(predictions[0][1]),
              "obscene" : float(predictions[0][2]),
              "insult" : float(predictions[0][3])}
  print(json.dumps(ins_dict))

test()
# -*- coding: utf-8 -*- insult_test.ipynb  Automatically generated by Colaboratory.  Original file is located at     https://colab.research.google.com/drive/1wYQD1axz8uxSIT9zxvnrb5AP5zFU8Yxy # Remove punctuations and numbers # Single character removal # Removing multiple spaces # loading