Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,44 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
+
from transformers import *
|
6 |
+
import json
|
7 |
+
import numpy as np
|
8 |
+
import pandas as pd
|
9 |
+
from tqdm import tqdm
|
10 |
+
import os
|
11 |
+
from tensorflow.python.client import device_lib
|
12 |
|
13 |
+
model = TFBertModel.from_pretrained('/huggingface_bert.h5')
|
14 |
+
|
15 |
+
def sentence_convert_data(data):
|
16 |
+
global tokenizer
|
17 |
+
tokens, masks, segments = [], [], []
|
18 |
+
token = tokenizer.encode(data, max_length=SEQ_LEN, truncation=True, padding='max_length')
|
19 |
+
|
20 |
+
num_zeros = token.count(0)
|
21 |
+
mask = [1]*(SEQ_LEN-num_zeros) + [0]*num_zeros
|
22 |
+
segment = [0]*SEQ_LEN
|
23 |
+
|
24 |
+
tokens.append(token)
|
25 |
+
segments.append(segment)
|
26 |
+
masks.append(mask)
|
27 |
+
|
28 |
+
tokens = np.array(tokens)
|
29 |
+
masks = np.array(masks)
|
30 |
+
segments = np.array(segments)
|
31 |
+
return [tokens, masks, segments]
|
32 |
+
|
33 |
+
def movie_evaluation_predict(sentence):
|
34 |
+
data_x = sentence_convert_data(sentence)
|
35 |
+
predict = sentiment_model.predict(data_x)
|
36 |
+
predict_value = np.ravel(predict)
|
37 |
+
predict_answer = np.round(predict_value,0).item()
|
38 |
+
|
39 |
+
print(predict_value)
|
40 |
+
|
41 |
+
if predict_answer == 0:
|
42 |
+
st.write("(부정 확률 : %.2f) 부정적인 영화 평가입니다." % (1.0-predict_value))
|
43 |
+
elif predict_answer == 1:
|
44 |
+
st.write("(긍정 확률 : %.2f) 긍정적인 영화 평가입니다." % predict_value)
|