sky4432 commited on
Commit
657d704
Β·
verified Β·
1 Parent(s): 5d454b4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from transformers import pipeline
4
+
5
+ # 1) 감성뢄석 λͺ¨λΈ 뢈러였기
6
+ sentiment_analyzer = pipeline(
7
+ "sentiment-analysis",
8
+ model="monologg/koelectra-base-finetuned-nsmc"
9
+ )
10
+
11
+ st.title("읡λͺ…κ²Œμ‹œνŒ 감성뢄석")
12
+
13
+ st.write("""
14
+ - CSV λ˜λŠ” Excel νŒŒμΌμ„ μ—…λ‘œλ“œν•΄μ£Όμ„Έμš”.
15
+ - 'content' μ—΄(λ˜λŠ” μ›ν•˜λŠ” μ—΄)에 κ²Œμ‹œκΈ€ ν…μŠ€νŠΈκ°€ μžˆλ‹€κ³  κ°€μ •ν•©λ‹ˆλ‹€.
16
+ - μ—…λ‘œλ“œ ν›„ '감성뢄석 μ‹€ν–‰' λ²„νŠΌμ„ λˆ„λ₯΄λ©΄, 각 글에 λŒ€ν•œ 긍정/λΆ€μ • λ ˆμ΄λΈ”κ³Ό μ μˆ˜κ°€ ν‘œμ‹œλ©λ‹ˆλ‹€.
17
+ """)
18
+
19
+ # 2) 파일 μ—…λ‘œλ“œ μœ„μ ―
20
+ uploaded_file = st.file_uploader("κ²Œμ‹œκΈ€ 파일 μ—…λ‘œλ“œ (CSV λ˜λŠ” XLSX)", type=["csv", "xlsx"])
21
+
22
+ if uploaded_file is not None:
23
+ # 3) CSV/XLSX νŒλ³„ ν›„ DataFrame λ‘œλ“œ
24
+ if uploaded_file.name.endswith(".csv"):
25
+ df = pd.read_csv(uploaded_file)
26
+ else: # xlsx
27
+ df = pd.read_excel(uploaded_file)
28
+
29
+ st.write("미리보기:")
30
+ st.dataframe(df.head()) # μ—…λ‘œλ“œν•œ 데이터 일뢀 확인
31
+
32
+ # 4) 감성뢄석 μ‹€ν–‰
33
+ if st.button("감성뢄석 μ‹€ν–‰"):
34
+ results_label = []
35
+ results_score = []
36
+
37
+ for text in df["content"]: # 'content' 열에 κ²Œμ‹œκΈ€μ΄ μžˆλ‹€κ³  κ°€μ •
38
+ # 감성뢄석
39
+ result = sentiment_analyzer(text)
40
+ label = result[0]['label'] # positive/negative
41
+ score = result[0]['score'] # 신뒰도(0~1)
42
+ results_label.append(label)
43
+ results_score.append(score)
44
+
45
+ df["sentiment_label"] = results_label
46
+ df["sentiment_score"] = results_score
47
+
48
+ # 5) κ²°κ³Ό ν‘œμ‹œ
49
+ st.write("감성뢄석 κ²°κ³Ό:")
50
+ st.dataframe(df)
51
+
52
+ st.write("μ•„λž˜ λ²„νŠΌμ„ 눌러 κ²°κ³Όλ₯Ό CSV둜 λ‹€μš΄λ‘œλ“œν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.")
53
+
54
+ # 6) CSV λ‹€μš΄λ‘œλ“œ λ²„νŠΌ
55
+ csv_data = df.to_csv(index=False).encode('utf-8-sig')
56
+ st.download_button(
57
+ label="κ²°κ³Ό CSV λ‹€μš΄λ‘œλ“œ",
58
+ data=csv_data,
59
+ file_name="sentiment_analysis_result.csv",
60
+ mime="text/csv"
61
+ )