Spaces:
Sleeping
Sleeping
Commit ·
ee40b81
1
Parent(s): b5825cb
Upload Gradio app for mental health analysis
Browse files
app.py
CHANGED
|
@@ -16,15 +16,42 @@
|
|
| 16 |
# title="Mindscape AI Therapist"
|
| 17 |
# ).launch()
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
import gradio as gr
|
| 20 |
from transformers import pipeline
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
classifier = pipeline("text-classification", model="coldnasser/depression-anxiety-mindscape")
|
| 23 |
|
| 24 |
def predict(text):
|
| 25 |
try:
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
return f"Error: {str(e)}"
|
| 29 |
|
| 30 |
-
gr.Interface(fn=predict, inputs="text", outputs="
|
|
|
|
|
|
| 16 |
# title="Mindscape AI Therapist"
|
| 17 |
# ).launch()
|
| 18 |
|
| 19 |
+
# import gradio as gr
|
| 20 |
+
# from transformers import pipeline
|
| 21 |
+
|
| 22 |
+
# classifier = pipeline("text-classification", model="coldnasser/depression-anxiety-mindscape")
|
| 23 |
+
|
| 24 |
+
# def predict(text):
|
| 25 |
+
# try:
|
| 26 |
+
# return classifier(text)
|
| 27 |
+
# except Exception as e:
|
| 28 |
+
# return f"Error: {str(e)}"
|
| 29 |
+
|
| 30 |
+
# gr.Interface(fn=predict, inputs="text", outputs="text", title="Mindscape").launch()
|
| 31 |
import gradio as gr
|
| 32 |
from transformers import pipeline
|
| 33 |
|
| 34 |
+
# Define the mapping from label to human-readable status
|
| 35 |
+
label_mapping = {
|
| 36 |
+
"LABEL_0": "Normal",
|
| 37 |
+
"LABEL_1": "Depression",
|
| 38 |
+
"LABEL_2": "Anxiety"
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
classifier = pipeline("text-classification", model="coldnasser/depression-anxiety-mindscape")
|
| 42 |
|
| 43 |
def predict(text):
|
| 44 |
try:
|
| 45 |
+
result = classifier(text)[0] # Get the first result
|
| 46 |
+
label = result['label']
|
| 47 |
+
score = result['score']
|
| 48 |
+
|
| 49 |
+
# Map the label to a human-readable value
|
| 50 |
+
human_label = label_mapping.get(label, label)
|
| 51 |
+
|
| 52 |
+
return {"label": human_label, "score": score}
|
| 53 |
except Exception as e:
|
| 54 |
return f"Error: {str(e)}"
|
| 55 |
|
| 56 |
+
gr.Interface(fn=predict, inputs="text", outputs="json", title="Mindscape").launch()
|
| 57 |
+
|