Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- README.md +34 -13
- app.py +62 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,13 +1,34 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
\---
|
| 2 |
+
|
| 3 |
+
title: Student Support-Seeking Language Demo
|
| 4 |
+
|
| 5 |
+
emoji: 🎓
|
| 6 |
+
|
| 7 |
+
colorFrom: blue
|
| 8 |
+
|
| 9 |
+
colorTo: purple
|
| 10 |
+
|
| 11 |
+
sdk: gradio
|
| 12 |
+
|
| 13 |
+
app\_file: app.py
|
| 14 |
+
|
| 15 |
+
pinned: false
|
| 16 |
+
|
| 17 |
+
\---
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
\# Student Support-Seeking Language Demo
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
This Space demonstrates a text-classification workflow deployed on Hugging Face Spaces.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
\## Important
|
| 30 |
+
|
| 31 |
+
This is an educational demo only. It is not a clinical, disciplinary, or surveillance tool.
|
| 32 |
+
|
| 33 |
+
It should not be used to diagnose mental health conditions or make high-stakes decisions.
|
| 34 |
+
|
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
MODEL_NAME = "cardiffnlp/twitter-roberta-base-emotion-multilabel-latest"
|
| 5 |
+
|
| 6 |
+
classifier = pipeline("text-classification", model=MODEL_NAME, top_k=None)
|
| 7 |
+
|
| 8 |
+
DISCLAIMER = """
|
| 9 |
+
This demo detects patterns in self-provided text that may indicate support-seeking or distress-related language.
|
| 10 |
+
It is for educational demonstration only and is NOT a diagnostic, disciplinary, or clinical tool.
|
| 11 |
+
If someone may be in immediate danger, contact emergency services or a qualified crisis resource.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
DISTRESS_KEYWORDS = {
|
| 15 |
+
"sadness", "fear", "anger", "disgust", "negative"
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
def analyze_text(text):
|
| 19 |
+
if not text or not text.strip():
|
| 20 |
+
return "Please enter some text.", {}
|
| 21 |
+
|
| 22 |
+
results = classifier(text[:512])[0]
|
| 23 |
+
|
| 24 |
+
label_scores = {item["label"]: float(item["score"]) for item in results}
|
| 25 |
+
|
| 26 |
+
distress_score = 0.0
|
| 27 |
+
for label, score in label_scores.items():
|
| 28 |
+
if label.lower() in DISTRESS_KEYWORDS:
|
| 29 |
+
distress_score += score
|
| 30 |
+
|
| 31 |
+
if distress_score >= 0.60:
|
| 32 |
+
assessment = "Potential support-seeking / distress-related language detected"
|
| 33 |
+
elif distress_score >= 0.30:
|
| 34 |
+
assessment = "Some distress-related language detected"
|
| 35 |
+
else:
|
| 36 |
+
assessment = "No strong distress-related language detected"
|
| 37 |
+
|
| 38 |
+
return assessment, label_scores
|
| 39 |
+
|
| 40 |
+
demo = gr.Interface(
|
| 41 |
+
fn=analyze_text,
|
| 42 |
+
inputs=gr.Textbox(
|
| 43 |
+
lines=6,
|
| 44 |
+
label="Student text input",
|
| 45 |
+
placeholder="Enter a message, reflection, or post for analysis..."
|
| 46 |
+
),
|
| 47 |
+
outputs=[
|
| 48 |
+
gr.Textbox(label="Assessment"),
|
| 49 |
+
gr.Label(label="Model scores")
|
| 50 |
+
],
|
| 51 |
+
title="Student Support-Seeking Language Demo",
|
| 52 |
+
description=DISCLAIMER,
|
| 53 |
+
examples=[
|
| 54 |
+
["I feel overwhelmed and I do not know who to talk to anymore."],
|
| 55 |
+
["I am stressed about finals but I think I can manage."],
|
| 56 |
+
["I had a good day and finished my homework."],
|
| 57 |
+
],
|
| 58 |
+
flagging_mode="never"
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|