AmiKim's picture
Update app.py
ae333c8 verified
import pandas as pd
from konlpy.tag import Okt
import gradio as gr
# ๊ฐ์„ฑ ์‚ฌ์ „ ๋กœ๋”ฉ
knu_lex = pd.read_csv('SentiWord_Dict.txt', sep='\t', names=['word', 'score', 'desc'])
# ํ˜•ํƒœ์†Œ ๋ถ„์„๊ธฐ
okt = Okt()
# ๊ฐ์ • ์ ์ˆ˜ ๊ณ„์‚ฐ ํ•จ์ˆ˜
def get_sentiment_score(text):
tokens = okt.morphs(text)
score = 0
matched_words = []
for token in tokens:
matched = knu_lex[knu_lex['word'] == token]
if not matched.empty:
token_score = int(matched.iloc[0]['score'])
score += token_score
matched_words.append(f"{token}({token_score})")
interpretation = ""
if score >= 2:
interpretation = "๐Ÿ˜Š ๊ธ์ •์ ์ธ ๋ฌธ์žฅ์ž…๋‹ˆ๋‹ค!"
elif score <= -2:
interpretation = "โ˜น๏ธ ๋ถ€์ •์ ์ธ ๋ฌธ์žฅ์ž…๋‹ˆ๋‹ค."
else:
interpretation = "๐Ÿ˜ ์ค‘๋ฆฝ์ ์ธ ๋ฌธ์žฅ์ž…๋‹ˆ๋‹ค."
return f"โ–ถ ๊ฐ์ • ์ ์ˆ˜: {score}\nโ–ถ ๊ฐ์ • ๋‹จ์–ด: {', '.join(matched_words)}\n\n{interpretation}"
# Gradio ์ธํ„ฐํŽ˜์ด์Šค
iface = gr.Interface(
fn=get_sentiment_score,
inputs=gr.Textbox(lines=3, placeholder="์นด์นด์˜คํ†ก ๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”"),
outputs="text",
title="KNU ๊ฐ์„ฑ์‚ฌ์ „ ๊ธฐ๋ฐ˜ ๊ฐ์ • ๋ถ„์„๊ธฐ",
description="์นด์นด์˜คํ†ก ๋“ฑ ๊ตฌ์–ด์ฒด ๋ฌธ์žฅ์„ ์ž…๋ ฅํ•˜๋ฉด ๊ฐ์ • ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ด์ค๋‹ˆ๋‹ค. (์‚ฌ์ „ ๊ธฐ๋ฐ˜ ๋ถ„์„)"
)
if __name__ == "__main__":
iface.launch()