File size: 14,817 Bytes
49c8013
b9ed42e
49c8013
 
2ffaad6
 
 
49c8013
 
2ffaad6
 
49c8013
 
 
 
 
 
 
 
2ffaad6
 
 
 
 
 
49c8013
2ffaad6
 
 
 
 
 
 
 
7dcaa5c
2ffaad6
 
 
 
 
 
62ea5f3
2ffaad6
 
 
 
 
 
 
 
 
 
 
 
49c8013
2ffaad6
49c8013
2ffaad6
 
49c8013
2ffaad6
62ea5f3
2ffaad6
 
 
 
 
 
49c8013
2ffaad6
 
49c8013
 
2ffaad6
 
 
 
49c8013
2ffaad6
 
 
 
 
49c8013
2ffaad6
 
 
 
 
 
 
129744f
 
2ffaad6
129744f
2ffaad6
49c8013
62ea5f3
 
2ffaad6
62ea5f3
2ffaad6
49c8013
2ffaad6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7dcaa5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ffaad6
 
 
 
 
 
 
 
 
 
62ea5f3
 
 
 
 
 
 
 
 
 
2ffaad6
 
 
 
 
 
 
 
 
 
49c8013
2ffaad6
 
 
 
 
 
49c8013
129744f
 
 
 
 
 
 
49c8013
2ffaad6
 
49c8013
 
2ffaad6
 
 
 
 
 
62ea5f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49c8013
 
2ffaad6
 
49c8013
 
2ffaad6
 
49c8013
2ffaad6
 
49c8013
7dcaa5c
 
 
 
 
 
 
2ffaad6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7dcaa5c
 
 
 
 
 
129744f
 
 
 
 
 
 
 
 
 
 
 
2ffaad6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129744f
 
2ffaad6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b9ed42e
 
 
 
 
 
 
 
 
 
 
 
 
 
62ea5f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b9ed42e
7dcaa5c
 
 
 
 
 
 
 
 
 
 
 
 
 
2ffaad6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49c8013
2ffaad6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49c8013
2ffaad6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49c8013
2ffaad6
 
 
 
49c8013
2ffaad6
 
 
 
 
 
 
 
 
 
129744f
 
 
 
2ffaad6
 
 
49c8013
2ffaad6
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
import json
from collections import Counter

import altair as alt
import japanize_matplotlib
import matplotlib.pyplot as plt
import nagisa
import pandas as pd
import streamlit as st
from datasets import load_dataset
from wordcloud import WordCloud


def read_json(file_name):
    with open(file_name, "r") as f:
        json_data = json.load(f)
    return json_data


@st.cache_data
def convert_to_dataframe():
    # Load a json file
    json_file = "awesome-japanese-nlp-resources-search.json"
    json_data = read_json(json_file)
    df = pd.DataFrame(json_data)

    # Sorted by selected columns
    df = df[
        [
            "project_name",
            "description",
            "url",
            "stargazers_count",
            "downloads",
            "model_architectures",
            "source",
            "score",
            "first_commit",
            "latest_commit",
            "languages",
            "model_or_dataset",
            "model_size",
        ]
    ]
    df = df.sort_values(by="score", ascending=False)

    # Convert DataFrame for Dashboard
    df["first_commit"] = pd.to_datetime(df["first_commit"], errors="coerce")
    df["latest_commit"] = pd.to_datetime(df["latest_commit"], errors="coerce")
    df["activity_period"] = (df["latest_commit"] - df["first_commit"]).dt.days
    df = df[df["first_commit"] >= "2009-01-01"]
    df = df[df["latest_commit"] >= "2009-01-01"]
    df["str_languages"] = df["languages"].apply(
        lambda x: ",".join(x) if isinstance(x, list) else str(x)
    )
    df["year"] = df["first_commit"].dt.year

    dataset = load_dataset("taishi-i/nagisa_stopwords")
    stopwords = dataset["nagisa_stopwords"]["words"]

    def tokenize_description(description):
        description = description.lower()
        tokens = nagisa.filter(description, filter_postags=["助詞", "εŠ©ε‹•θ©ž"])
        words = tokens.words
        words = [word for word in words if len(word.strip()) > 0]
        words = [word for word in words if word not in stopwords]
        words = " ".join(words)
        return words

    df["tokenized_description"] = df["description"].apply(tokenize_description)
    return df


def main():
    # Set streamlit page settings
    title = "Awesome Japanese NLP resources Dashboard"
    icon = "πŸ”Ž"

    st.set_page_config(
        page_title=title,
        page_icon=icon,
        layout="wide",
        initial_sidebar_state="expanded",
    )
    df = convert_to_dataframe()

    # Main streamlit page (sidebar)
    alt.themes.enable("dark")
    with st.sidebar:
        st.title(f"{title} {icon}")
        st.markdown(
            "You can search for open-source software from [1250+ Japanese NLP"
            " repositories](https://github.com/taishi-i/awesome-japanese-nlp-resources)."
        )

        query = st.text_input(label="Search keyword")

        # source_type = ["GitHub", "Hugging Face"]
        source_type = ["Hugging Face", "GitHub"]
        selected_source_type = st.selectbox(
            "Choose a source type: Hugging Face or GitHub", source_type
        )

        # Filtering GitHub or Hugging Face
        df = df[df["source"] == selected_source_type]

        if selected_source_type == "GitHub":
            selected_model_or_dataset = None
            all_languages = (
                df["languages"]
                .dropna()
                .apply(lambda x: x if isinstance(x, list) else [])
                .explode()
                .unique()
            )
            all_languages = [""] + all_languages.tolist()
            selected_languges = st.selectbox(
                "Choose a programming language", all_languages, index=0
            )

            min_stars = int(df["stargazers_count"].min())
            max_stars = int(df["stargazers_count"].max())

            stars_range = st.slider(
                "Choose the range for the stargazer count",
                min_value=min_stars,
                max_value=max_stars,
                value=(min_stars, max_stars),
            )
        else:
            selected_languges = None
            selected_model_or_dataset = st.selectbox(
                "Choose a model or a dataset",
                ["", "model", "dataset"],
                index=0,
            )

            model_architectures = df["model_architectures"].tolist()
            model_architectures_counts = Counter(model_architectures)
            del model_architectures_counts[None]

            model_architectures_counts = sorted(
                model_architectures_counts.items(),
                key=lambda x: x[1],
                reverse=True,
            )
            model_architectures_list = [""] + [
                model_and_count[0]
                for model_and_count in model_architectures_counts
            ]

            selected_model_architecture = st.selectbox(
                "Choose a model architecture",
                model_architectures_list,
                index=0,
            )

            min_downloads = int(df["downloads"].min())
            max_downloads = int(df["downloads"].max())

            downloads_range = st.slider(
                "Choose the range for the number of downloads",
                min_value=min_downloads,
                max_value=max_downloads,
                value=(min_downloads, max_downloads),
            )

            min_model_size = int(df["model_size"].min())
            max_model_size = int(df["model_size"].max())

            model_size_range = st.slider(
                "Choose the range for the model size (billion)",
                min_value=min_model_size,
                max_value=max_model_size,
                value=(min_model_size, max_model_size),
            )

        min_activity_period = int(df["activity_period"].min())
        max_activity_period = int(df["activity_period"].max())

        activity_period_range = st.slider(
            "Select the range for activity periods (in days)",
            min_value=min_activity_period,
            max_value=max_activity_period,
            value=(min_activity_period, max_activity_period),
        )
        years = sorted(list(set(df["year"].dropna().astype(int).tolist())))

        selected_year_range = st.slider(
            "Select a range for the years of the first commit",
            min_value=min(years),
            max_value=max(years),
            value=(min(years), max(years)),
        )

        st.markdown("Sorted by")
        num_show_repos = st.number_input(
            "Number of sorted repositories", value=15
        )
        latest_repos_btn = st.button("Latest repositories")
        trend_repos_btn = st.button("Trend repositories")

    df = df[
        (df["year"] >= selected_year_range[0])
        & (df["year"] <= selected_year_range[1])
    ]

    if selected_source_type == "GitHub":
        df = df[
            (df["stargazers_count"] >= stars_range[0])
            & (df["stargazers_count"] <= stars_range[1])
        ]
    else:
        if (
            downloads_range[0] > min_downloads
            or downloads_range[1] < max_downloads
        ):
            df = df[
                (df["downloads"] >= downloads_range[0])
                & (df["downloads"] <= downloads_range[1])
            ]

        if (
            model_size_range[0] > min_model_size
            or model_size_range[1] < max_model_size
        ):
            df = df[
                (df["model_size"] >= model_size_range[0])
                & (df["model_size"] <= model_size_range[1])
            ]

    df = df[
        (df["activity_period"] >= activity_period_range[0])
        & (df["activity_period"] <= activity_period_range[1])
    ]

    contained_description = df["description"].str.contains(
        query, case=False, na=False
    )
    contained_project_name = df["project_name"].str.contains(
        query, case=False, na=False
    )
    contained_model_arch = df["model_architectures"].str.contains(
        query, case=False, na=False
    )

    df = df[
        contained_description | contained_project_name | contained_model_arch
    ]

    if selected_languges:
        df = df[
            df["str_languages"].str.contains(
                selected_languges, case=False, na=False
            )
        ]

    if selected_model_or_dataset:
        df = df[
            df["model_or_dataset"].str.contains(
                selected_model_or_dataset, case=False, na=False
            )
        ]

    if selected_model_architecture:
        contained_model_arch = df["model_architectures"].str.contains(
            selected_model_architecture, case=False, na=False
        )
        df = df[contained_model_arch]

    if latest_repos_btn:
        df = df.sort_values(by="first_commit", ascending=False)
        df = df[:num_show_repos]

    if trend_repos_btn:
        if selected_source_type == "GitHub":
            stats_key = "stargazers_count"
        else:
            stats_key = "downloads"
        df = df.sort_values(by=stats_key, ascending=False)
        df = df[:num_show_repos]

    # Main streamlit page (columns)
    col1, col2 = st.columns(2, gap="large")

    with col1:
        st.markdown("### DataFrame")
        st.markdown(f"#### Number of repositories: {len(df)}")
        if selected_source_type == "GitHub":
            stats_key = "stargazers_count"
        else:
            stats_key = "downloads"

        if len(df) > 0:
            mean_value = int(df[stats_key].mean())
            min_value = int(df[stats_key].min())
            max_value = int(df[stats_key].max())
            st.markdown(
                f"#### {stats_key} mean: {int(mean_value)}, min: {min_value},"
                f" max: {max_value}"
            )

        st.dataframe(df, height=600)

        if len(df) > 0:
            st.markdown("### Word Cloud")
            descriptions = df["tokenized_description"].tolist()
            combined_text = " ".join(descriptions)

            wordcloud = WordCloud(
                width=800,
                height=400,
                font_path=japanize_matplotlib.get_font_ttf_path(),
                max_words=50,
                colormap="PuBu",
            ).generate(combined_text)

            fig, ax = plt.subplots()
            ax.imshow(wordcloud, interpolation="bilinear")
            ax.axis("off")
            st.pyplot(fig, use_container_width=True)

        if selected_source_type == "GitHub":
            all_languages = [
                language
                for languages_list in df["languages"]
                for language in languages_list
            ]
            language_counts = Counter(all_languages)
            language_df = pd.DataFrame(
                language_counts.items(), columns=["Language", "Count"]
            )
            language_df = language_df.sort_values(by="Count", ascending=False)

            st.markdown("### Language Usage Table")
            st.dataframe(language_df)
        else:
            st.markdown("### Model size vs downloads")
            chart = (
                alt.Chart(df)
                .mark_circle(size=60)
                .encode(
                    x="model_size",
                    y="downloads",
                    tooltip=["project_name", "model_size", "downloads"],
                )
                .properties(
                    title=(
                        "Relationship between model size (Billion) and"
                        " downloads"
                    ),
                )
                .interactive()
            )
            st.altair_chart(chart, use_container_width=True)

            model_architectures = df["model_architectures"].tolist()
            model_architectures_counts = Counter(model_architectures)
            del model_architectures_counts[None]
            model_architectures_df = pd.DataFrame(
                model_architectures_counts.items(),
                columns=["Model_architectures", "Count"],
            )
            model_architectures_df = model_architectures_df.sort_values(
                by="Count", ascending=False
            )

            st.markdown("### Model Architecture Table")
            st.dataframe(model_architectures_df)

    with col2:
        if selected_source_type == "GitHub":
            vs_type = "stargazers_count"
        else:
            vs_type = "downloads"

        st.markdown(f"### First commit vs {vs_type}")
        chart = (
            alt.Chart(df)
            .mark_circle(size=60)
            .encode(
                x="first_commit:T",
                y=f"{vs_type}:Q",
                tooltip=["first_commit", "project_name", f"{vs_type}"],
            )
            .properties(
                title=f"Relationship between first commit date and {vs_type}",
            )
            .interactive()
        )
        st.altair_chart(chart, use_container_width=True)

        st.markdown(f"### Latest commit vs {vs_type}")
        chart = (
            alt.Chart(df)
            .mark_circle(size=60)
            .encode(
                x="latest_commit:T",
                y=f"{vs_type}:Q",
                tooltip=["project_name", "latest_commit", f"{vs_type}"],
            )
            .properties(
                title=f"Relationship between latest commit date and {vs_type}",
            )
            .interactive()
        )
        st.altair_chart(chart, use_container_width=True)

        st.markdown(f"### Activity period vs {vs_type}")
        chart = (
            alt.Chart(df)
            .mark_circle(size=60)
            .encode(
                x=alt.X("activity_period:Q", title="Activity Period (Days)"),
                y=alt.Y(f"{vs_type}:Q", title=f"{vs_type}"),
                tooltip=[
                    "project_name",
                    "activity_period",
                    f"{vs_type}",
                ],
            )
            .properties(
                title=f"Relationship between activity period and {vs_type}",
            )
            .interactive()
        )
        st.altair_chart(chart, use_container_width=True)

        projects_per_year = (
            df.groupby("year").size().reset_index(name="project_count")
        )

        chart = (
            alt.Chart(projects_per_year)
            .mark_bar()
            .encode(
                x=alt.X("year:O", title="Year"),
                y=alt.Y("project_count:Q", title="Number of repositories"),
                tooltip=["year", "project_count"],
            )
            .properties(
                title=(
                    "Number of projects per year based on the uear of the"
                    " first commit"
                ),
                width=600,
                height=400,
            )
        )

        st.altair_chart(chart, use_container_width=True)


if __name__ == "__main__":
    main()