aandrei404's picture
Update app.py
b6d1755
raw
history blame contribute delete
796 Bytes
import os
import gradio as gr
import pandas as pd
import tensorflow as tf
from tensorflow.keras.layers import TextVectorization
df = pd.read_csv(os.path.join('.', 'train.csv'))
loaded_vect_model = tf.keras.models.load_model('vect')
vectorizer = loaded_vect_model.layers[0]
model = tf.keras.models.load_model('toxicity.h5')
def score_comment(comment):
vectorized_comment = vectorizer([comment])
results = model.predict(vectorized_comment)
text = ''
for idx, col in enumerate(df.columns[2:]):
text += '{}: {}\n'.format(col, results[0][idx]>0.5)
return text
interface = gr.Interface(fn=score_comment,
inputs=gr.Textbox(lines=2, placeholder='Comment to score'),
outputs='text')
interface.queue()
interface.launch()