File size: 2,122 Bytes
657d704
 
 
 
 
 
 
6dc20d1
 
657d704
 
 
 
 
 
6dc20d1
657d704
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7aff10e
657d704
6dc20d1
657d704
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import streamlit as st
import pandas as pd
from transformers import pipeline

# 1) 감성뢄석 λͺ¨λΈ 뢈러였기
sentiment_analyzer = pipeline(
    "sentiment-analysis",
    model="monologg/koelectra-base-finetuned-nsmc",
    truncation=True
)

st.title("읡λͺ…κ²Œμ‹œνŒ 감성뢄석")

st.write("""
- CSV λ˜λŠ” Excel νŒŒμΌμ„ μ—…λ‘œλ“œν•΄μ£Όμ„Έμš”.
- 'λ‚΄μš©' μ—΄(λ˜λŠ” μ›ν•˜λŠ” μ—΄)에 κ²Œμ‹œκΈ€ ν…μŠ€νŠΈκ°€ μžˆλ‹€κ³  κ°€μ •ν•©λ‹ˆλ‹€.
- μ—…λ‘œλ“œ ν›„ '감성뢄석 μ‹€ν–‰' λ²„νŠΌμ„ λˆ„λ₯΄λ©΄, 각 글에 λŒ€ν•œ 긍정/λΆ€μ • λ ˆμ΄λΈ”κ³Ό μ μˆ˜κ°€ ν‘œμ‹œλ©λ‹ˆλ‹€.
""")

# 2) 파일 μ—…λ‘œλ“œ μœ„μ ―
uploaded_file = st.file_uploader("κ²Œμ‹œκΈ€ 파일 μ—…λ‘œλ“œ (CSV λ˜λŠ” XLSX)", type=["csv", "xlsx"])

if uploaded_file is not None:
    # 3) CSV/XLSX νŒλ³„ ν›„ DataFrame λ‘œλ“œ
    if uploaded_file.name.endswith(".csv"):
        df = pd.read_csv(uploaded_file)
    else:  # xlsx
        df = pd.read_excel(uploaded_file)
    
    st.write("미리보기:")
    st.dataframe(df.head())  # μ—…λ‘œλ“œν•œ 데이터 일뢀 확인
    
    # 4) 감성뢄석 μ‹€ν–‰
    if st.button("감성뢄석 μ‹€ν–‰"):
        results_label = []
        results_score = []
        
        for text in df["λ‚΄μš©"]:  
            # 감성뢄석
            result = sentiment_analyzer(text, truncation=True)
            label = result[0]['label']        # positive/negative
            score = result[0]['score']        # 신뒰도(0~1)
            results_label.append(label)
            results_score.append(score)
        
        df["sentiment_label"] = results_label
        df["sentiment_score"] = results_score
        
        # 5) κ²°κ³Ό ν‘œμ‹œ
        st.write("감성뢄석 κ²°κ³Ό:")
        st.dataframe(df)
        
        st.write("μ•„λž˜ λ²„νŠΌμ„ 눌러 κ²°κ³Όλ₯Ό CSV둜 λ‹€μš΄λ‘œλ“œν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.")
        
        # 6) CSV λ‹€μš΄λ‘œλ“œ λ²„νŠΌ
        csv_data = df.to_csv(index=False).encode('utf-8-sig')
        st.download_button(
            label="κ²°κ³Ό CSV λ‹€μš΄λ‘œλ“œ",
            data=csv_data,
            file_name="sentiment_analysis_result.csv",
            mime="text/csv"
        )