Spaces:
Sleeping
Sleeping
File size: 1,996 Bytes
44a44ec 5cf47d0 | 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | import gradio as gr
from transformers import pipeline
MODEL_NAME = "cardiffnlp/twitter-roberta-base-emotion-multilabel-latest"
classifier = pipeline("text-classification", model=MODEL_NAME, top_k=None)
DISCLAIMER = """
This demo detects patterns in self-provided text that may indicate support-seeking or distress-related language.
It is for educational demonstration only and is NOT a diagnostic, disciplinary, or clinical tool.
If someone may be in immediate danger, contact emergency services or a qualified crisis resource.
"""
DISTRESS_KEYWORDS = {
"sadness", "fear", "anger", "disgust", "negative"
}
def analyze_text(text):
if not text or not text.strip():
return "Please enter some text.", {}
results = classifier(text[:512])[0]
label_scores = {item["label"]: float(item["score"]) for item in results}
distress_score = 0.0
for label, score in label_scores.items():
if label.lower() in DISTRESS_KEYWORDS:
distress_score += score
if distress_score >= 0.60:
assessment = "Potential support-seeking / distress-related language detected"
elif distress_score >= 0.30:
assessment = "Some distress-related language detected"
else:
assessment = "No strong distress-related language detected"
return assessment, label_scores
demo = gr.Interface(
fn=analyze_text,
inputs=gr.Textbox(
lines=6,
label="Student text input",
placeholder="Enter a message, reflection, or post for analysis..."
),
outputs=[
gr.Textbox(label="Assessment"),
gr.Label(label="Model scores")
],
title="Student Support-Seeking Language Demo",
description=DISCLAIMER,
examples=[
["I feel overwhelmed and I do not know who to talk to anymore."],
["I am stressed about finals but I think I can manage."],
["I had a good day and finished my homework."],
],
allow_flagging="never"
)
if __name__ == "__main__":
demo.launch() |