Spaces:
Runtime error
Runtime error
| 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() | |