File size: 1,286 Bytes
3c28019
 
 
71dafc2
3c28019
 
71dafc2
ac84e50
 
71dafc2
 
3c28019
71dafc2
3c28019
 
 
 
35aa952
3c28019
 
 
 
24d3701
3c28019
 
71dafc2
3c28019
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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()