juyam commited on
Commit
48a03c1
·
verified ·
1 Parent(s): e1c5792

removed submit button , sorted the result

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -3,20 +3,26 @@ import re
3
  from collections import Counter
4
 
5
  def count_finnish_words(text):
 
6
  # フィンランド語の特殊文字を含む単語のみを抽出(数字は除外)
7
  words = re.findall(r'[a-zA-ZåäöÅÄÖ_]+', text.lower())
8
 
9
  # 単語の出現回数をカウント
10
- word_counts = dict(Counter(words))
11
 
12
- return word_counts
 
 
 
13
 
 
14
  demo = gr.Interface(
15
  fn=count_finnish_words,
16
  inputs=gr.Textbox(lines=10, placeholder="ここにフィンランド語の文章を入力してください..."),
17
  outputs=gr.JSON(),
18
  title="フィンランド語単語カウントツール",
19
- description="入力されたフィンランド語の文章から単語の出現回数を集計します(数字は除外)"
 
20
  )
21
 
22
  # アプリケーションの起動
 
3
  from collections import Counter
4
 
5
  def count_finnish_words(text):
6
+ # テキストを前処理
7
  # フィンランド語の特殊文字を含む単語のみを抽出(数字は除外)
8
  words = re.findall(r'[a-zA-ZåäöÅÄÖ_]+', text.lower())
9
 
10
  # 単語の出現回数をカウント
11
+ word_counts = Counter(words)
12
 
13
+ # 出現回数の多い順にソート
14
+ sorted_word_counts = dict(sorted(word_counts.items(), key=lambda item: item[1], reverse=True))
15
+
16
+ return sorted_word_counts
17
 
18
+ # Gradioインターフェースの作成(日本語のタイトルと説明)
19
  demo = gr.Interface(
20
  fn=count_finnish_words,
21
  inputs=gr.Textbox(lines=10, placeholder="ここにフィンランド語の文章を入力してください..."),
22
  outputs=gr.JSON(),
23
  title="フィンランド語単語カウントツール",
24
+ description="入力されたフィンランド語の文章から単語の出現回数を集計します(数字は除外します",
25
+ live=True # 入力データが変更されるたびに自動的に処理
26
  )
27
 
28
  # アプリケーションの起動