Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
inputs=gr.Textbox(lines=3, placeholder="コメントを入力してください"),
|
| 19 |
outputs="text",
|
| 20 |
-
title="
|
| 21 |
description="ネガティブワードをチェックするよ"
|
| 22 |
-
)
|
|
|
|
|
|
|
|
|
| 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()
|