sakamoto84 commited on
Commit
9c182eb
·
verified ·
1 Parent(s): ba98497

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -1,22 +1,31 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # 感情分析モデルの読み込み
5
- classifier = pipeline("sentiment-analysis", model="jarvisx17/japanese-sentiment-analysis")
6
 
7
- # NGワードリスト
8
- NG_WORDS = ["あほ", "ばか", "くそ", "死ね", "むかつく", "うざい", "しね", "バカ", "アホ"]
 
 
 
 
 
9
 
10
- def classify_comment(comment):
11
- if any(ng in comment for ng in NG_WORDS):
12
- return "❌ 不適切なコメント(NGワード検出)"
13
  result = classifier(comment)[0]
14
- return f"判定結果: {result['label']} (スコア: {result['score']:.2f})"
 
15
 
16
- gr.Interface(
17
- fn=classify_comment,
 
 
 
 
 
18
  inputs=gr.Textbox(lines=3, placeholder="コメントを入力してください"),
19
  outputs="text",
20
- title="ネガティブワード発見くん",
21
  description="ネガティブワードをチェックするよ"
22
- ).launch()
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ classifier = pipeline("sentiment-analysis", model="mr4/bert-base-jp-sentiment-analysis")
 
5
 
6
+ NG_WORDS = ["あほ", "ばか", "くそ", "死ね", "うざい", "ムカつく", "きもい", "消えろ"]
7
+
8
+ def classify_comment_with_ng(comment):
9
+
10
+ for word in NG_WORDS:
11
+ if word in comment:
12
+ return f"❌ 不適切なコメント!(NGワード検出: '{word}')"
13
 
 
 
 
14
  result = classifier(comment)[0]
15
+ label = result["label"]
16
+ score = result["score"]
17
 
18
+ if label.lower() in ["negative"]:
19
+ return f"⚠ それはネガティブだよ... : {label} (スコア: {score:.2f})"
20
+ else:
21
+ return f"✅ ポジティブでいいね! : {label} (スコア: {score:.2f})"
22
+
23
+ iface = gr.Interface(
24
+ fn=classify_comment_with_ng,
25
  inputs=gr.Textbox(lines=3, placeholder="コメントを入力してください"),
26
  outputs="text",
27
+ title="ネガティブコメント検出くん",
28
  description="ネガティブワードをチェックするよ"
29
+ )
30
+
31
+ iface.launch()