pradanaadn's picture
Update app.py
35aa952 verified
import gradio as gr
from transformers import pipeline
classifier = pipeline("sentiment-analysis", model="pradanaadn/sucidal-text-classification-distillbert")
def text_classification(text):
label_mapping = {
'LABEL_0': 'Non-Suicide',
'LABEL_1': 'Suicide',
}
result= classifier(text)
sentiment_label = label_mapping[result[0]['label']]
sentiment_score = result[0]['score']
formatted_output = f"This sentiment is {sentiment_label} with the probability {sentiment_score*100:.2f}%"
return formatted_output
examples=["It's been a rollercoaster lately. One moment I'm on top of the world, full of energy, and the next, I'm down in the dumps, feeling hopeless", "I can't keep going like this anymore. Everything feels hopeless, and I don't see a way out. I feel like the world would be better off without me."]
io = gr.Interface(fn=text_classification,
inputs= gr.Textbox(lines=2, label="Text", placeholder="Enter title here..."),
outputs=gr.Textbox(lines=2, label="Text Classification Result"),
title="Suicidal Intent Detection",
description="Enter a text and see the text classification result!",
examples=examples)
io.launch()