JUNGU commited on
Commit
209776b
·
verified ·
1 Parent(s): 8d34983

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +31 -4
src/streamlit_app.py CHANGED
@@ -641,9 +641,25 @@ elif menu == "기사 분석하기":
641
  with keyword_tab1:
642
  keywords = analyze_keywords(selected_article['content'])
643
 
644
- # 시각화
645
  df = pd.DataFrame(keywords, columns=['단어', '빈도수'])
646
- st.bar_chart(df.set_index('단어'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
647
 
648
  st.write("**주요 키워드:**")
649
  for word, count in keywords:
@@ -728,11 +744,22 @@ elif menu == "기사 분석하기":
728
  }"""},
729
  {"role": "user", "content": f"다음 뉴스 기사를 분석해 주세요:\n\n제목: {selected_article['title']}\n\n내용: {selected_article['content'][:1500]}"}
730
  ],
731
- max_tokens=800
 
732
  )
733
 
 
 
 
 
734
  # JSON 파싱
735
- analysis_result = json.loads(response.choices[0].message.content)
 
 
 
 
 
 
736
 
737
  # 결과 시각화
738
  st.subheader("감정 분석 결과")
 
641
  with keyword_tab1:
642
  keywords = analyze_keywords(selected_article['content'])
643
 
644
+ # Plotly를 사용한 시각화
645
  df = pd.DataFrame(keywords, columns=['단어', '빈도수'])
646
+ fig = go.Figure(data=[
647
+ go.Bar(
648
+ x=df['단어'],
649
+ y=df['빈도수'],
650
+ marker_color='rgb(55, 83, 109)'
651
+ )
652
+ ])
653
+
654
+ fig.update_layout(
655
+ title='키워드 빈도 분석',
656
+ xaxis_title='키워드',
657
+ yaxis_title='빈도수',
658
+ height=500,
659
+ margin=dict(l=50, r=50, t=80, b=50)
660
+ )
661
+
662
+ st.plotly_chart(fig, use_container_width=True)
663
 
664
  st.write("**주요 키워드:**")
665
  for word, count in keywords:
 
744
  }"""},
745
  {"role": "user", "content": f"다음 뉴스 기사를 분석해 주세요:\n\n제목: {selected_article['title']}\n\n내용: {selected_article['content'][:1500]}"}
746
  ],
747
+ max_tokens=800,
748
+ response_format={ "type": "json_object" } # JSON 응답 형식 강제
749
  )
750
 
751
+ # 응답 내용 확인 및 디버깅
752
+ content = response.choices[0].message.content
753
+ logging.info(f"API 응답: {content}")
754
+
755
  # JSON 파싱
756
+ try:
757
+ analysis_result = json.loads(content)
758
+ except json.JSONDecodeError as e:
759
+ logging.error(f"JSON 파싱 오류: {str(e)}")
760
+ logging.error(f"파싱 시도한 내용: {content}")
761
+ st.error("API 응답을 파싱하는 중 오류가 발생했습니다. 응답 형식이 올바르지 않습니다.")
762
+ return
763
 
764
  # 결과 시각화
765
  st.subheader("감정 분석 결과")