Commit
•
2a702e3
1
Parent(s):
682685b
Delete main.py
Browse files
main.py
DELETED
@@ -1,39 +0,0 @@
|
|
1 |
-
# Importing Data
|
2 |
-
import os
|
3 |
-
import pandas as pd
|
4 |
-
import tensorflow as tf
|
5 |
-
import numpy as np
|
6 |
-
import gradio as gr
|
7 |
-
|
8 |
-
# Data preparation
|
9 |
-
|
10 |
-
df = pd.read_csv(r"train.csv.zip")
|
11 |
-
|
12 |
-
# Creating Word Embeddings
|
13 |
-
from tensorflow import TextVectorization
|
14 |
-
X = df['comment_text']
|
15 |
-
y = df[df.columns[2:]].values
|
16 |
-
MAX_FEATURES = 200000
|
17 |
-
vectorizer = TextVectorization(max_tokens = MAX_FEATURES, output_sequence_length = 1800, output_mode = 'int')
|
18 |
-
vectorizer.adapt(X.values)
|
19 |
-
vectorized_text = vectorizer(X.values)
|
20 |
-
print('Vectorization Complete!')
|
21 |
-
|
22 |
-
# Loading The Model
|
23 |
-
model = tf.keras.models.load_model('hate_model.h5')
|
24 |
-
|
25 |
-
# To display results
|
26 |
-
def score_comment(comment):
|
27 |
-
vectorize_comment = vectorizer([comment])
|
28 |
-
results = model.predict(vectorize_comment)
|
29 |
-
|
30 |
-
text = ''
|
31 |
-
for idx, col in enumerate(df.columns[2:]):
|
32 |
-
text += '{}: {}\n'.format(col, results[0][idx]>0.5)
|
33 |
-
|
34 |
-
return text
|
35 |
-
|
36 |
-
interface = gr.Interface(fn=score_comment,
|
37 |
-
inputs=gr.inputs.Textbox(lines=2, placeholder='Comment to score'),
|
38 |
-
outputs='text')
|
39 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|