morizon commited on
Commit
88573b4
1 Parent(s): b4954f0

Add application file

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +69 -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)
requirements.txt ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==4.2.2
2
+ attrs==22.2.0
3
+ blinker==1.5
4
+ cachetools==5.3.0
5
+ certifi==2022.12.7
6
+ charset-normalizer==3.0.1
7
+ click==8.1.3
8
+ contourpy==1.0.7
9
+ cycler==0.11.0
10
+ decorator==5.1.1
11
+ entrypoints==0.4
12
+ fonttools==4.38.0
13
+ fst-pso==1.8.1
14
+ funcy==1.18
15
+ future==0.18.3
16
+ FuzzyTM==2.0.5
17
+ gensim==4.3.0
18
+ gitdb==4.0.10
19
+ GitPython==3.1.31
20
+ idna==3.4
21
+ importlib-metadata==6.0.0
22
+ importlib-resources==5.12.0
23
+ Jinja2==3.1.2
24
+ joblib==1.2.0
25
+ jsonschema==4.17.3
26
+ kiwisolver==1.4.4
27
+ markdown-it-py==2.2.0
28
+ MarkupSafe==2.1.2
29
+ matplotlib==3.7.0
30
+ mdurl==0.1.2
31
+ miniful==0.0.6
32
+ numexpr==2.8.4
33
+ numpy==1.24.2
34
+ packaging==23.0
35
+ pandas==1.5.3
36
+ Pillow==9.4.0
37
+ protobuf==3.20.3
38
+ pyarrow==11.0.0
39
+ pydeck==0.8.0
40
+ pyFUME==0.2.25
41
+ Pygments==2.14.0
42
+ pyLDAvis==3.3.1
43
+ Pympler==1.0.1
44
+ pyparsing==3.0.9
45
+ pyrsistent==0.19.3
46
+ python-dateutil==2.8.2
47
+ pytz==2022.7.1
48
+ pytz-deprecation-shim==0.1.0.post0
49
+ requests==2.28.2
50
+ rich==13.3.1
51
+ scikit-learn==1.2.1
52
+ scipy==1.10.0
53
+ semver==2.13.0
54
+ simpful==2.9.0
55
+ six==1.16.0
56
+ sklearn==0.0.post1
57
+ smart-open==6.3.0
58
+ smmap==5.0.0
59
+ streamlit==1.19.0
60
+ threadpoolctl==3.1.0
61
+ toml==0.10.2
62
+ toolz==0.12.0
63
+ tornado==6.2
64
+ typing_extensions==4.5.0
65
+ tzdata==2022.7
66
+ tzlocal==4.2
67
+ urllib3==1.26.14
68
+ validators==0.20.0
69
+ zipp==3.14.0