soojeongcrystal commited on
Commit
cae38ec
·
verified ·
1 Parent(s): afc37aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -29
app.py CHANGED
@@ -39,11 +39,25 @@ def generate_colors(n):
39
  return ['#%02x%02x%02x' % tuple(int(x*255) for x in colorsys.hsv_to_rgb(*hsv)) for hsv in HSV_tuples]
40
 
41
  # Streamlit 앱 설정
42
- st.title('한국어 토픽 모델링 앱')
43
 
44
- # CSS를 사용하여 테이블 스타일 정의
45
  st.markdown("""
46
  <style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  .stDataFrame {
48
  width: 100%;
49
  }
@@ -59,6 +73,19 @@ st.markdown("""
59
  </style>
60
  """, unsafe_allow_html=True)
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  # 사이드바 설정
63
  st.sidebar.header('설정')
64
 
@@ -181,6 +208,7 @@ if uploaded_file is not None:
181
  anthropic = Anthropic(api_key=api_key)
182
 
183
  st.header("Claude의 토픽 해석")
 
184
  for idx, topic in enumerate(lda.components_):
185
  with st.spinner(f"토픽 {idx + 1} 해석 중..."):
186
  lda_top_words = [feature_names[i] for i in topic.argsort()[:-11:-1]]
@@ -208,33 +236,26 @@ if uploaded_file is not None:
208
  )
209
  st.subheader(f"토픽 {idx + 1} 해석:")
210
  st.write(response.completion)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  else:
212
  st.warning("Claude API 키가 설정되지 않았습니다. https://console.anthropic.com/settings/keys 에 접속하여 API 키를 발급받으시면 토픽명과 해석을 제공받으실 수 있습니다.")
213
 
214
- # CSS를 사용하여 푸터 스타일 정의
215
- footer_style = """
216
- <style>
217
- .footer {
218
- position: fixed;
219
- left: 0;
220
- bottom: 0;
221
- width: 100%;
222
- background-color: #f1f1f1;
223
- color: black;
224
- text-align: center;
225
- padding: 30px;
226
- font-size: 20px;
227
- z-index: 999;
228
- }
229
- </style>
230
- """
231
-
232
- # 푸터 HTML
233
- footer_html = footer_style + """
234
- <div class="footer">
235
- mySUNI 행복 College 행복담당조직 Meet-Up
236
- </div>
237
- """
238
-
239
- # 푸터 렌더링
240
- st.markdown(footer_html, unsafe_allow_html=True)
 
39
  return ['#%02x%02x%02x' % tuple(int(x*255) for x in colorsys.hsv_to_rgb(*hsv)) for hsv in HSV_tuples]
40
 
41
  # Streamlit 앱 설정
42
+ st.set_page_config(layout="wide") # 페이지를 와이드 모드로 설정
43
 
44
+ # CSS를 사용하여 헤더와 테이블 스타일 정의
45
  st.markdown("""
46
  <style>
47
+ .header {
48
+ position: fixed;
49
+ top: 0;
50
+ right: 0;
51
+ background-color: #f1f1f1;
52
+ color: black;
53
+ text-align: right;
54
+ padding: 10px 20px;
55
+ font-size: 16px;
56
+ z-index: 999;
57
+ }
58
+ .main-content {
59
+ margin-top: 60px; # 헤더의 높이만큼 여백 추가
60
+ }
61
  .stDataFrame {
62
  width: 100%;
63
  }
 
73
  </style>
74
  """, unsafe_allow_html=True)
75
 
76
+ # 헤더 HTML
77
+ header_html = """
78
+ <div class="header">
79
+ mySUNI 행복 College 행복담당조직 Meet-Up
80
+ </div>
81
+ """
82
+
83
+ # 헤더 렌더링
84
+ st.markdown(header_html, unsafe_allow_html=True)
85
+
86
+ st.markdown('<div class="main-content">', unsafe_allow_html=True)
87
+ st.title('한국어 토픽 모델링 앱')
88
+
89
  # 사이드바 설정
90
  st.sidebar.header('설정')
91
 
 
208
  anthropic = Anthropic(api_key=api_key)
209
 
210
  st.header("Claude의 토픽 해석")
211
+ topic_interpretations = []
212
  for idx, topic in enumerate(lda.components_):
213
  with st.spinner(f"토픽 {idx + 1} 해석 중..."):
214
  lda_top_words = [feature_names[i] for i in topic.argsort()[:-11:-1]]
 
236
  )
237
  st.subheader(f"토픽 {idx + 1} 해석:")
238
  st.write(response.completion)
239
+
240
+ # 토픽명과 분포를 저장
241
+ topic_name = response.completion.split("토픽명 제안:")[1].split("\n")[0].strip()
242
+ topic_interpretations.append((idx + 1, topic_name, df_weights.iloc[idx]['퍼센트']))
243
+
244
+ # 종합 해석
245
+ st.header("토픽 종합 해석")
246
+ summary_prompt = f"{HUMAN_PROMPT} 다음은 토픽 모델링 결과로 나온 각 토픽의 이름과 분포입니다. 이를 바탕으로 전체 문서의 주제를 종합적으로 해석해주세요:\n\n"
247
+ for topic_num, topic_name, topic_percent in topic_interpretations:
248
+ summary_prompt += f"토픽 {topic_num}: {topic_name} ({topic_percent:.1f}%)\n"
249
+ summary_prompt += "\n위 정보를 바탕으로 전체 문서의 주제를 3-4문장으로 종합해서 설명해주세요."
250
+
251
+ summary_response = anthropic.completions.create(
252
+ model="claude-2.1",
253
+ max_tokens_to_sample=1000,
254
+ prompt=f"{summary_prompt}\n\n{AI_PROMPT}",
255
+ )
256
+ st.write(summary_response.completion)
257
+
258
  else:
259
  st.warning("Claude API 키가 설정되지 않았습니다. https://console.anthropic.com/settings/keys 에 접속하여 API 키를 발급받으시면 토픽명과 해석을 제공받으실 수 있습니다.")
260
 
261
+ st.markdown('</div>', unsafe_allow_html=True)