Reyall commited on
Commit
1204cc2
·
verified ·
1 Parent(s): 31457f3

Upload 9 files

Browse files
best_model/label_encoder.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0b18fdaa0f8bb34ed643d679d56a1091fa6553747e5389ac4940640909dd8d57
3
+ size 3374
best_model/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7af82a381817471667b142e55198705b2a852262e2353585e68c8f14547dcaff
3
+ size 439155212
best_model/requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ transformers>=4.30.0
2
+ altair
3
+ pandas
4
+ streamlit
5
+ torch
6
+ scikit-learn
7
+ requests
best_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
+ }
best_model/tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 512,
51
+ "never_split": null,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "strip_accents": null,
55
+ "tokenize_chinese_chars": true,
56
+ "tokenizer_class": "BertTokenizer",
57
+ "unk_token": "[UNK]"
58
+ }
best_model/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7119bd5212d6defb5990d470323a16b95a015f97af1161842fba1d73aa559185
3
+ size 5240
best_model/vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ transformers>=4.30.0
2
+ altair
3
+ pandas
4
+ gradio
5
+ torch
6
+ scikit-learn
7
+ requests
streamlit_app.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ import streamlit as st
4
+ from transformers import BertTokenizer, BertForSequenceClassification # Burada BertTokenizer istifadə edirik
5
+ import torch
6
+ import pickle
7
+ import random
8
+ from collections import defaultdict
9
+ import requests
10
+
11
+ # GitHub-dan fayl yükləmək üçün funksiyanın təyin edilməsi
12
+ def download_label_encoder():
13
+ url = "https://github.com/AxundovReyal/nlp-disease/raw/main/label_encoder.pkl"
14
+ headers = {
15
+ "Authorization": f"token {os.getenv('GITHUB_TOKEN')}" # GitHub personal access token mühit dəyişəni olaraq qeyd olunmalı
16
+ }
17
+ response = requests.get(url, headers=headers)
18
+
19
+ if response.status_code == 200:
20
+ with open("label_encoder.pkl", "wb") as f:
21
+ f.write(response.content)
22
+ print("label_encoder.pkl faylı uğurla yükləndi.")
23
+ else:
24
+ raise Exception(f"Fayl yüklənə bilmədi, error kodu: {response.status_code}")
25
+
26
+ # Modelin və label_encoder-in yüklənməsi
27
+ @st.cache_resource
28
+ def load_model():
29
+ # GitHub-dan label_encoder yükləmək
30
+ download_label_encoder()
31
+
32
+ # Label encoder yüklənməsi əvvəlcə edilir
33
+ with open("label_encoder.pkl", "rb") as f:
34
+ label_encoder = pickle.load(f)
35
+
36
+ # Burada AutoTokenizer əvəzinə BertTokenizer istifadə edirik
37
+ tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') # BERT Tokenizer
38
+ model = BertForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=len(label_encoder.classes_)) # BERT Model
39
+
40
+ model.eval()
41
+
42
+ return tokenizer, model, label_encoder
43
+
44
+ tokenizer, model, label_encoder = load_model()
45
+
46
+ st.title("Disease NLP Classifier")
47
+
48
+ text = st.text_area("Enter your symptoms separated by commas (e.g. fever, cough, headache):")
49
+
50
+ def predict(text_input):
51
+ inputs = tokenizer(text_input, return_tensors="pt", truncation=True, padding=True, max_length=128)
52
+ with torch.no_grad():
53
+ outputs = model(**inputs)
54
+ probs = torch.nn.functional.softmax(outputs.logits, dim=-1).squeeze()
55
+ return probs
56
+
57
+ if st.button("Predict"):
58
+ if not text.strip():
59
+ st.warning("Please enter some symptoms!")
60
+ else:
61
+ symptoms = [s.strip() for s in text.split(",") if s.strip()]
62
+ if not symptoms:
63
+ st.warning("Please enter valid symptoms separated by commas!")
64
+ else:
65
+ agg_probs = defaultdict(float)
66
+ n_shuffles = 10
67
+ for _ in range(n_shuffles):
68
+ random.shuffle(symptoms)
69
+ shuffled_text = ", ".join(symptoms)
70
+ probs = predict(shuffled_text)
71
+ for i, p in enumerate(probs):
72
+ agg_probs[i] += p.item()
73
+ for k in agg_probs:
74
+ agg_probs[k] /= n_shuffles
75
+ top_3 = sorted(agg_probs.items(), key=lambda x: x[1], reverse=True)[:3]
76
+
77
+ st.subheader("Top 3 Predicted Diseases (averaged over shuffled inputs):")
78
+ for idx, prob in top_3:
79
+ label = label_encoder.classes_[idx] # Etiketləri doğru alırıq
80
+ st.write(f"**{label}** — Probability: `{prob * 100:.2f}%`")
81
+
82
+ # Render port düzəlişi
83
+ if __name__ == "__main__":
84
+ port = int(os.environ.get("PORT", 8501))
85
+ sys.argv = ["streamlit", "run", "streamlit_app.py", f"--server.port={port}", "--server.address=0.0.0.0"]
86
+ from streamlit.web.cli import main
87
+ sys.exit(main())