Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
-
|
|
|
|
| 5 |
from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer
|
| 6 |
from sklearn.decomposition import LatentDirichletAllocation
|
| 7 |
from konlpy.tag import Okt
|
|
@@ -296,7 +297,7 @@ if 'run_analysis' in st.session_state and st.session_state.run_analysis:
|
|
| 296 |
st.table(topic_summary_df)
|
| 297 |
|
| 298 |
def interpret_topics(api_key, topic_results):
|
| 299 |
-
client = Anthropic(api_key=api_key)
|
| 300 |
|
| 301 |
prompt = f"""다음은 LDA 토픽 모델링 결과로 나온 각 토픽의 정보입니다. 이를 바탕으로 전체 토픽을 종합적으로 해석해주세요:
|
| 302 |
|
|
@@ -336,19 +337,19 @@ if 'run_analysis' in st.session_state and st.session_state.run_analysis:
|
|
| 336 |
위 형식에 맞춰 답변해주세요. 사용자가 쉽게 복사하여 사용할 수 있도록 간결하고 명확하게 작성해주세요.
|
| 337 |
"""
|
| 338 |
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
|
| 353 |
# Claude API를 사용한 토픽 해석 부분
|
| 354 |
if api_key:
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
+
import anthropic
|
| 5 |
+
import json
|
| 6 |
from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer
|
| 7 |
from sklearn.decomposition import LatentDirichletAllocation
|
| 8 |
from konlpy.tag import Okt
|
|
|
|
| 297 |
st.table(topic_summary_df)
|
| 298 |
|
| 299 |
def interpret_topics(api_key, topic_results):
|
| 300 |
+
client = anthropic.Anthropic(api_key=api_key)
|
| 301 |
|
| 302 |
prompt = f"""다음은 LDA 토픽 모델링 결과로 나온 각 토픽의 정보입니다. 이를 바탕으로 전체 토픽을 종합적으로 해석해주세요:
|
| 303 |
|
|
|
|
| 337 |
위 형식에 맞춰 답변해주세요. 사용자가 쉽게 복사하여 사용할 수 있도록 간결하고 명확하게 작성해주세요.
|
| 338 |
"""
|
| 339 |
|
| 340 |
+
try:
|
| 341 |
+
response = client.messages.create(
|
| 342 |
+
model="claude-3-sonnet-20240229",
|
| 343 |
+
max_tokens=4000,
|
| 344 |
+
temperature=0,
|
| 345 |
+
system="당신은 토픽 모델링과 텍스트 분석 전문가입니다. 토픽 모델링 결과에 대해 명확하고 간결하며 상세한 해석을 제공합니다. 모든 응답은 반드시 한국어로만 작성해야 합니다.",
|
| 346 |
+
messages=[
|
| 347 |
+
{"role": "user", "content": prompt}
|
| 348 |
+
]
|
| 349 |
+
)
|
| 350 |
+
return response.content[0].text
|
| 351 |
+
except Exception as e:
|
| 352 |
+
return f"Claude API 호출 중 오류가 발생했습니다: {str(e)}"
|
| 353 |
|
| 354 |
# Claude API를 사용한 토픽 해석 부분
|
| 355 |
if api_key:
|