def test_output(): post_URL = request.args.get("postURL") eg_subreddit = fu.subreddit(post_URL) postAtt = fu.rcommentLink(post_URL) eg_postTitle = postAtt.title eg_comment = [comment.body for comment in postAtt.comments][0] commentCreated = int([comment.created_utc for comment in postAtt.comments][0]) postCreated = postAtt.created_utc timeDiffC = fu.timePresent(round(commentCreated - postCreated)) timeDiffCur = fu.timePresent(round(time.time() - commentCreated)) comLength = fu.cLength(fu.comLength(eg_comment)) sentiment = "" sentiment = fu.sentiment(eg_comment) features = fu.features(eg_subreddit, post_URL, eg_comment, commentCreated) eg_prob = "" eg_prob = fu.probability(features) eg_score = [comment.score for comment in postAtt.comments][0] eg_commentForm = fu.commentSent(eg_comment) return render_template( "testOutput.html", eg_postTitle=eg_postTitle, eg_commentForm=eg_commentForm, eg_score=eg_score, eg_prob=eg_prob, sentiment=sentiment, comLength=comLength, timeDiffCur=timeDiffCur, timeDiffC=timeDiffC, eg_comment=eg_comment, post_URL=post_URL, eg_subreddit=eg_subreddit, )
def output(): post = request.args.get("post") comment = request.args.get("comment") postAtt = fu.rcommentLink(post) postTitle = postAtt.title the_subreddit = "" the_subreddit = fu.subreddit(post) the_post = "" the_post = post your_comment = "" your_comment = comment features = fu.features(the_subreddit, post, comment, time.time()) timePost = "" timePost = fu.timePresent(features[4]) comLength = "" comLength = fu.cLength(features[5]) sentiment = "" sentiment = fu.sentiment(your_comment) prob = "" prob = fu.probability(features) commentForm = fu.commentSent(your_comment) return render_template( "output.html", postTitle=postTitle, commentForm=commentForm, prob=prob, timePost=timePost, comLength=comLength, sentiment=sentiment, the_subreddit=the_subreddit, the_post=the_post, your_comment=your_comment, )
model_lstm = tf.keras.models.load_model('model_lstm.h5') with open('full_word.dat','rb') as fp: full_word = pickle.load(fp) with open('naver_count.dat', 'rb') as fp: naver_count = pickle.load(fp) with open('sentiment_pipe.dat', 'rb') as fp: pipe = pickle.load(fp) with open('sentiment_word2vec.dat', 'rb') as fp: model = pickle.load(fp) from konlpy.tag import Okt import numpy as np okt =Okt() mapped_review, review_p = review_process(review) r = model_lstm.predict(mapped_review) pos=0 neg=0 for _ in range(len(review_p)): try: w2v_proba = sentiment(review_p[_]) if w2v_proba >= 0.6 and r[_][0] ==0: neg+=1 else: pos+=1 except: pass print(f'긍정적 리뷰 비율 : {pos/(pos+neg)*100}, 부정적 리뷰 비율: {neg/(pos+neg)*100}')
def get_sentiment(chat_id): return fnc.sentiment(get_chat(chat_id))