Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

app.py 1.6 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  1. import pickle
  2. import gradio as gr
  3. from keras.models import load_model
  4. from keras.preprocessing.sequence import pad_sequences
  5. from src.config import *
  6. from src.data_cleaning import clean_text
  7. # -------------------------------------------------------------------------
  8. lstm_model = load_model(MODEL_LOCATION)
  9. with open(TOKENIZER_LOCATION, 'rb') as handle:
  10. tokenizer = pickle.load(handle)
  11. # -------------------------------------------------------------------------
  12. def make_prediction(input_comment):
  13. input_comment = clean_text(input_comment)
  14. input_comment = input_comment.split(" ")
  15. sequences = tokenizer.texts_to_sequences(input_comment)
  16. sequences = [[item for sublist in sequences for item in sublist]]
  17. padded_data = pad_sequences(sequences, maxlen=MAX_SEQUENCE_LENGTH)
  18. result = lstm_model.predict(padded_data, len(padded_data), verbose=1)
  19. return \
  20. {
  21. "Toxic": str(result[0][0]),
  22. "Very Toxic": str(result[0][1]),
  23. "Obscene": str(result[0][2]),
  24. "Threat": str(result[0][3]),
  25. "Insult": str(result[0][4]),
  26. "Hate": str(result[0][5]),
  27. "Neutral": str(result[0][6])
  28. }
  29. comment = gr.inputs.Textbox(lines=20, placeholder="Enter your comment!!")
  30. title = "Toxic Comment Classifier"
  31. description = "This application uses a Long Short-Term Memory (LSTM) Recurrent Neural Network (RNN) " \
  32. "model to predict the inappropriateness of a comment"
  33. gr.Interface(fn=make_prediction,
  34. inputs=comment,
  35. outputs="label",
  36. title=title,
  37. description=description).launch()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...