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()