Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ import altair as alt
|
|
| 11 |
import colorsys
|
| 12 |
import networkx as nx
|
| 13 |
import streamlit.components.v1 as components
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
# Streamlit 페이지 설정
|
|
@@ -121,11 +122,11 @@ st.markdown("""
|
|
| 121 |
</div>
|
| 122 |
""", unsafe_allow_html=True)
|
| 123 |
|
| 124 |
-
st.title('토픽모델링
|
| 125 |
|
| 126 |
# 사이드바 설정
|
| 127 |
with st.sidebar:
|
| 128 |
-
st.header('설정')
|
| 129 |
|
| 130 |
# Claude API 키 설정
|
| 131 |
api_key = st.text_input("Claude API 키를 입력하세요", type="password")
|
|
@@ -133,7 +134,7 @@ with st.sidebar:
|
|
| 133 |
api_key = os.environ.get("ANTHROPIC_API_KEY")
|
| 134 |
|
| 135 |
# API 키에 대한 추가 설명
|
| 136 |
-
st.caption("Claude API가 있으면 토픽 종합 해석까지 가능합니다. 공백으로
|
| 137 |
|
| 138 |
# 불용어 설정
|
| 139 |
stop_words_input = st.text_area("불용어 목록 (쉼표로 구분)", ', '.join(default_stop_words))
|
|
@@ -245,7 +246,7 @@ if 'run_analysis' in st.session_state and st.session_state.run_analysis:
|
|
| 245 |
text = base.mark_text(
|
| 246 |
align='center',
|
| 247 |
baseline='middle',
|
| 248 |
-
dy=-10
|
| 249 |
).encode(
|
| 250 |
text=alt.Text('비중:Q', format='.1f')
|
| 251 |
)
|
|
@@ -272,6 +273,7 @@ if 'run_analysis' in st.session_state and st.session_state.run_analysis:
|
|
| 272 |
html_content = create_custom_network_html(G)
|
| 273 |
components.html(html_content, height=500)
|
| 274 |
|
|
|
|
| 275 |
# Claude API를 사용하여 토픽 해석
|
| 276 |
if api_key:
|
| 277 |
client = anthropic.Anthropic(api_key=api_key)
|
|
@@ -313,12 +315,12 @@ if 'run_analysis' in st.session_state and st.session_state.run_analysis:
|
|
| 313 |
|
| 314 |
response = client.messages.create(
|
| 315 |
model="claude-3-5-sonnet-20240620",
|
| 316 |
-
max_tokens=3000,
|
| 317 |
messages=[
|
| 318 |
{"role": "user", "content": f"{prompt}\n\n{AI_PROMPT}"}
|
| 319 |
]
|
| 320 |
)
|
| 321 |
-
|
| 322 |
st.subheader("토픽 모델링 종합 결과")
|
| 323 |
st.text_area("결과를 복사하여 사용하세요:", value=response.completion, height=500)
|
| 324 |
else:
|
|
|
|
| 11 |
import colorsys
|
| 12 |
import networkx as nx
|
| 13 |
import streamlit.components.v1 as components
|
| 14 |
+
import anthropic
|
| 15 |
|
| 16 |
|
| 17 |
# Streamlit 페이지 설정
|
|
|
|
| 122 |
</div>
|
| 123 |
""", unsafe_allow_html=True)
|
| 124 |
|
| 125 |
+
st.title('📊토픽모델링 for SK')
|
| 126 |
|
| 127 |
# 사이드바 설정
|
| 128 |
with st.sidebar:
|
| 129 |
+
st.header('설정하기')
|
| 130 |
|
| 131 |
# Claude API 키 설정
|
| 132 |
api_key = st.text_input("Claude API 키를 입력하세요", type="password")
|
|
|
|
| 134 |
api_key = os.environ.get("ANTHROPIC_API_KEY")
|
| 135 |
|
| 136 |
# API 키에 대한 추가 설명
|
| 137 |
+
st.caption("Claude API가 있으면 토픽 종합 해석까지 가능합니다. 공백으로 두면 기본적인 결과만 나옵니다.")
|
| 138 |
|
| 139 |
# 불용어 설정
|
| 140 |
stop_words_input = st.text_area("불용어 목록 (쉼표로 구분)", ', '.join(default_stop_words))
|
|
|
|
| 246 |
text = base.mark_text(
|
| 247 |
align='center',
|
| 248 |
baseline='middle',
|
| 249 |
+
dy=-10
|
| 250 |
).encode(
|
| 251 |
text=alt.Text('비중:Q', format='.1f')
|
| 252 |
)
|
|
|
|
| 273 |
html_content = create_custom_network_html(G)
|
| 274 |
components.html(html_content, height=500)
|
| 275 |
|
| 276 |
+
|
| 277 |
# Claude API를 사용하여 토픽 해석
|
| 278 |
if api_key:
|
| 279 |
client = anthropic.Anthropic(api_key=api_key)
|
|
|
|
| 315 |
|
| 316 |
response = client.messages.create(
|
| 317 |
model="claude-3-5-sonnet-20240620",
|
| 318 |
+
max_tokens=3000,
|
| 319 |
messages=[
|
| 320 |
{"role": "user", "content": f"{prompt}\n\n{AI_PROMPT}"}
|
| 321 |
]
|
| 322 |
)
|
| 323 |
+
|
| 324 |
st.subheader("토픽 모델링 종합 결과")
|
| 325 |
st.text_area("결과를 복사하여 사용하세요:", value=response.completion, height=500)
|
| 326 |
else:
|