Spaces:
Runtime error
Runtime error
File size: 1,388 Bytes
6b16f50 5be445d 6f926b9 5be445d ae333c8 5be445d 6b16f50 5be445d 3c8a2e1 5be445d 6b16f50 5be445d 5099da2 5be445d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 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()
|