Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import re | |
| from collections import Counter | |
| def count_finnish_words(text): | |
| # テキストを前処理 | |
| # フィンランド語の特殊文字を含む単語のみを抽出(数字は除外) | |
| words = re.findall(r'[a-zA-ZåäöÅÄÖ_]+', text.lower()) | |
| # 単語の出現回数をカウント | |
| word_counts = Counter(words) | |
| # 出現回数の多い順にソート | |
| sorted_word_counts = dict(sorted(word_counts.items(), key=lambda item: item[1], reverse=True)) | |
| return sorted_word_counts | |
| # Gradioインターフェースの作成(日本語のタイトルと説明) | |
| demo = gr.Interface( | |
| fn=count_finnish_words, | |
| inputs=gr.Textbox(lines=10, placeholder="ここにフィンランド語の文章を入力してください..."), | |
| outputs=gr.JSON(), | |
| title="フィンランド語単語カウントツール", | |
| description="入力されたフィンランド語の文章から単語の出現回数を集計します(数字は除外します)。", | |
| live=True # 入力データが変更されるたびに自動的に処理 | |
| ) | |
| # アプリケーションの起動 | |
| if __name__ == "__main__": | |
| demo.launch() |