File size: 1,462 Bytes
3c28019 71dafc2 3c28019 71dafc2 3c28019 71dafc2 3c28019 71dafc2 3c28019 532fc12 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 28 29 30 31 32 |
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': 'Anxiety',
'LABEL_1': 'Bipolar',
'LABEL_2': 'Depression',
'LABEL_3': 'Normal',
'LABEL_4': 'Personality disorder',
'LABEL_5': 'Stress',
'LABEL_6': 'Suicidal',
}
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've noticed that my reactions and feelings often don't match what others expect. It creates tension in my relationships, and sometimes I feel like I'm not in control of myself."]
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="Mental Health Classification",
description="Enter a text and see the text classification result!",
examples=examples)
io.launch() |