comment_filter / app.py
duwing's picture
Update app.py
c19ce1c verified
raw
history blame
1.32 kB
import streamlit as st
import tensorflow as tf
import numpy as np
import pandas as pd
from transformers import *
import json
import numpy as np
import pandas as pd
from tqdm import tqdm
import os
from tensorflow.python.client import device_lib
model = TFBertModel.from_pretrained('./huggingface_bert.h5')
def sentence_convert_data(data):
global tokenizer
tokens, masks, segments = [], [], []
token = tokenizer.encode(data, max_length=SEQ_LEN, truncation=True, padding='max_length')
num_zeros = token.count(0)
mask = [1]*(SEQ_LEN-num_zeros) + [0]*num_zeros
segment = [0]*SEQ_LEN
tokens.append(token)
segments.append(segment)
masks.append(mask)
tokens = np.array(tokens)
masks = np.array(masks)
segments = np.array(segments)
return [tokens, masks, segments]
def movie_evaluation_predict(sentence):
data_x = sentence_convert_data(sentence)
predict = sentiment_model.predict(data_x)
predict_value = np.ravel(predict)
predict_answer = np.round(predict_value,0).item()
print(predict_value)
if predict_answer == 0:
st.write("(λΆ€μ • ν™•λ₯  : %.2f) 뢀정적인 μ˜ν™” ν‰κ°€μž…λ‹ˆλ‹€." % (1.0-predict_value))
elif predict_answer == 1:
st.write("(긍정 ν™•λ₯  : %.2f) 긍정적인 μ˜ν™” ν‰κ°€μž…λ‹ˆλ‹€." % predict_value)