Opsifiz commited on
Commit
8508cf7
·
1 Parent(s): 6938a69

Add application file

Browse files
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+ import contractions
5
+ import html
6
+ import re
7
+
8
+ # Load model and tokenizer
9
+ model_path = "my_model" # directory with your trained model
10
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
11
+ model = AutoModelForSequenceClassification.from_pretrained(model_path)
12
+
13
+ # Labels
14
+ id2label = {
15
+ 0: 'Anxiety',
16
+ 1: 'BPD',
17
+ 2: 'Normal',
18
+ 3: 'bipolar',
19
+ 4: 'depression',
20
+ 5: 'mentalillness',
21
+ 6: 'schizophrenia'
22
+ }
23
+
24
+ # Inference function
25
+ def predict(text):
26
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
27
+ with torch.no_grad():
28
+ outputs = model(**inputs)
29
+ pred_id = outputs.logits.argmax(dim=1).item()
30
+ return id2label[pred_id]
31
+
32
+ def clean_text(text):
33
+ text = str(text)
34
+ text = text.lower()
35
+ text = contractions.fix(text)
36
+ text = html.unescape(text)
37
+ text = re.sub(r'http\S+', '', text) # Remove URLs
38
+ text = re.sub(r'[^a-zA-Z\s]', '', text) # Remove special characters
39
+ text = re.sub(r'\s+', ' ', text).strip()
40
+ return text
41
+
42
+ # Gradio UI
43
+ demo = gr.Interface(
44
+ fn=predict,
45
+ inputs=gr.Textbox(lines=3, placeholder="Enter text here..."),
46
+ outputs=gr.Label(),
47
+ title="Mental Health Text Classifier",
48
+ description="Predicts mental health category based on text input."
49
+ )
50
+
51
+ if __name__ == "__main__":
52
+ demo.launch()
my_model/config.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "activation": "gelu",
3
+ "architectures": [
4
+ "DistilBertForSequenceClassification"
5
+ ],
6
+ "attention_dropout": 0.1,
7
+ "dim": 768,
8
+ "dropout": 0.1,
9
+ "hidden_dim": 3072,
10
+ "id2label": {
11
+ "0": "LABEL_0",
12
+ "1": "LABEL_1",
13
+ "2": "LABEL_2",
14
+ "3": "LABEL_3",
15
+ "4": "LABEL_4",
16
+ "5": "LABEL_5",
17
+ "6": "LABEL_6"
18
+ },
19
+ "initializer_range": 0.02,
20
+ "label2id": {
21
+ "LABEL_0": 0,
22
+ "LABEL_1": 1,
23
+ "LABEL_2": 2,
24
+ "LABEL_3": 3,
25
+ "LABEL_4": 4,
26
+ "LABEL_5": 5,
27
+ "LABEL_6": 6
28
+ },
29
+ "max_position_embeddings": 512,
30
+ "model_type": "distilbert",
31
+ "n_heads": 12,
32
+ "n_layers": 6,
33
+ "pad_token_id": 0,
34
+ "problem_type": "single_label_classification",
35
+ "qa_dropout": 0.1,
36
+ "seq_classif_dropout": 0.2,
37
+ "sinusoidal_pos_embds": false,
38
+ "tie_weights_": true,
39
+ "torch_dtype": "float32",
40
+ "transformers_version": "4.51.3",
41
+ "vocab_size": 30522
42
+ }
my_model/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:39a4924aae12999707576d94fab86410a96602f4ad8e7b2c267f6b2eda9ac89a
3
+ size 267847948
my_model/special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
my_model/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
my_model/tokenizer_config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": false,
45
+ "cls_token": "[CLS]",
46
+ "do_lower_case": true,
47
+ "extra_special_tokens": {},
48
+ "mask_token": "[MASK]",
49
+ "model_max_length": 512,
50
+ "pad_token": "[PAD]",
51
+ "sep_token": "[SEP]",
52
+ "strip_accents": null,
53
+ "tokenize_chinese_chars": true,
54
+ "tokenizer_class": "DistilBertTokenizer",
55
+ "unk_token": "[UNK]"
56
+ }
my_model/vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio
4
+ contractions
5
+ html
6
+ re