import gradio as gr from transformers import pipeline classifier = pipeline("sentiment-analysis", model="mr4/bert-base-jp-sentiment-analysis") NG_WORDS = ["あほ", "ばか", "くそ", "死ね", "うざい", "ムカつく", "きもい", "消えろ"] def classify_comment_with_ng(comment): for word in NG_WORDS: if word in comment: return f"❌ 不適切なコメント!(NGワード検出: '{word}')" result = classifier(comment)[0] label = result["label"] score = result["score"] if label.lower() in ["negative"]: return f"⚠ それはネガティブだから言っちゃだめだよ! : {label} (スコア: {score:.2f})" else: return f"✅ ポジティブでいいね! : {label} (スコア: {score:.2f})" iface = gr.Interface( fn=classify_comment_with_ng, inputs=gr.Textbox(lines=3, placeholder="コメントを入力してください"), outputs="text", title="ネガティブコメント検出くん", description="ネガティブコメントをチェックするよ" ) iface.launch()