kawayui commited on
Commit
d6f7f2a
1 Parent(s): b1eba7b

Add answer source of app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ from gensim.corpora import Dictionary, MmCorpus
4
+ from gensim.models import LdaModel, Word2Vec
5
+ import matplotlib.pyplot as plt
6
+ import streamlit as st
7
+ from pyLDAvis import prepared_data_to_html
8
+ import pyLDAvis.gensim_models as gensimvis
9
+
10
+ # 生データ・コーパス・辞書・モデルのロード
11
+ df = pd.read_csv("./raw_corpus.csv")
12
+ corpus = MmCorpus('./corpus.mm')
13
+ dict = Dictionary.load(f'./livedoor_demo.dict')
14
+ lda = LdaModel.load('./lda_demo.model')
15
+
16
+ st.caption("生データ一覧")
17
+ st.dataframe(df.iloc[:100])
18
+
19
+ st.caption("記事のカテゴリ")
20
+ fig, ax = plt.subplots()
21
+ count = df[["CATEGORY", "DOCUMENT"]].groupby("CATEGORY").count()
22
+ count.plot.pie(y="DOCUMENT", ax=ax, ylabel="", legend=False)
23
+ st.pyplot(fig)
24
+
25
+ # pyLDAvisによるトピックの可視化
26
+ vis = gensimvis.prepare(lda, corpus, dict)
27
+ html_string = prepared_data_to_html(vis)
28
+ st.components.v1.html(html_string, width=1300, height=800)