Spaces:
Sleeping
Sleeping
Commit ·
50ca3c6
0
Parent(s):
Duplicate from shibinashraf/drugrecommendationsystem
Browse filesCo-authored-by: shibin ashraf <shibinashraf@users.noreply.huggingface.co>
- .gitattributes +35 -0
- README.md +14 -0
- app.py +80 -0
- data/custom_dataset.csv +3 -0
- model/passmodel.pkl +3 -0
- model/tfidfvectorizer.pkl +3 -0
- names.txt +11 -0
- requirements.txt +17 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
data/custom_dataset.csv filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Drugrecommendationsystem
|
| 3 |
+
emoji: 🔥
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: yellow
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: 1.17.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
duplicated_from: shibinashraf/drugrecommendationsystem
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import re
|
| 5 |
+
import nltk
|
| 6 |
+
nltk.download('wordnet')
|
| 7 |
+
nltk.download('stopwords')
|
| 8 |
+
|
| 9 |
+
import streamlit as st
|
| 10 |
+
import numpy as np
|
| 11 |
+
from nltk.stem import WordNetLemmatizer
|
| 12 |
+
from nltk.corpus import stopwords
|
| 13 |
+
from bs4 import BeautifulSoup
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# Model saved with Keras model.save()
|
| 17 |
+
MODEL_PATH = 'model/passmodel.pkl'
|
| 18 |
+
TOKENIZER_PATH ='model/tfidfvectorizer.pkl'
|
| 19 |
+
DATA_PATH ='data/custom_dataset.csv'
|
| 20 |
+
|
| 21 |
+
# loading vectorizer
|
| 22 |
+
vectorizer = joblib.load(TOKENIZER_PATH)
|
| 23 |
+
# loading model
|
| 24 |
+
model = joblib.load(MODEL_PATH)
|
| 25 |
+
#getting stopwords
|
| 26 |
+
stop = stopwords.words('english')
|
| 27 |
+
lemmatizer = WordNetLemmatizer()
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
st.set_page_config(page_title='PDDRS', page_icon='👨⚕️',layout = 'wide')
|
| 31 |
+
st.title("💉 Patient Diagnosis and Drug Recommendation System 💉")
|
| 32 |
+
st.header("Enter Patient Condition:")
|
| 33 |
+
raw_text = st.text_input('')
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def predict(raw_text):
|
| 37 |
+
global predicted_cond
|
| 38 |
+
global top_drugs
|
| 39 |
+
if raw_text != "":
|
| 40 |
+
clean_text = cleanText(raw_text)
|
| 41 |
+
clean_lst = [clean_text]
|
| 42 |
+
tfidf_vect = vectorizer.transform(clean_lst)
|
| 43 |
+
prediction = model.predict(tfidf_vect)
|
| 44 |
+
predicted_cond = prediction[0]
|
| 45 |
+
df = pd.read_csv(DATA_PATH)
|
| 46 |
+
top_drugs = top_drugs_extractor(predicted_cond,df)
|
| 47 |
+
|
| 48 |
+
def cleanText(raw_review):
|
| 49 |
+
# 1. Delete HTML
|
| 50 |
+
review_text = BeautifulSoup(raw_review, 'html.parser').get_text()
|
| 51 |
+
# 2. Make a space
|
| 52 |
+
letters_only = re.sub('[^a-zA-Z]', ' ', review_text)
|
| 53 |
+
# 3. lower letters
|
| 54 |
+
words = letters_only.lower().split()
|
| 55 |
+
# 5. Stopwords
|
| 56 |
+
meaningful_words = [w for w in words if not w in stop]
|
| 57 |
+
# 6. lemmitization
|
| 58 |
+
lemmitize_words = [lemmatizer.lemmatize(w) for w in meaningful_words]
|
| 59 |
+
# 7. space join words
|
| 60 |
+
return( ' '.join(lemmitize_words))
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def top_drugs_extractor(condition,df):
|
| 64 |
+
df_top = df[(df['rating']>=9)&(df['usefulCount']>=90)].sort_values(by = ['rating', 'usefulCount'], ascending = [False, False])
|
| 65 |
+
drug_lst = df_top[df_top['condition']==condition]['drugName'].head(4).tolist()
|
| 66 |
+
drug_lst =[*set(drug_lst)]
|
| 67 |
+
return drug_lst
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
predict_button = st.button("Predict")
|
| 71 |
+
|
| 72 |
+
if predict_button:
|
| 73 |
+
predict(raw_text)
|
| 74 |
+
st.header('Condition Predicted')
|
| 75 |
+
st.subheader(predicted_cond)
|
| 76 |
+
st.header('Top Recommended Drugs')
|
| 77 |
+
for i in range(0,len(top_drugs)):
|
| 78 |
+
st.subheader(top_drugs[i])
|
| 79 |
+
|
| 80 |
+
|
data/custom_dataset.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:39bdc6a910fbfef9b506524047861166c3cf184fa4a3275b8ba958833f3bdbd7
|
| 3 |
+
size 12230423
|
model/passmodel.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c149cb32e7f154571527d3744e940277d3446e657dc0202b04df3afc54a8e9a0
|
| 3 |
+
size 32354028
|
model/tfidfvectorizer.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:65ffa88aa305ae86fb683d58b397a9260ac1153d3fb381412d4575ac5b14e5e5
|
| 3 |
+
size 27603137
|
names.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Pharmacovigilance System using Sentiment Analysis of Drug Reviews for Disease Diagnosis and Treatment Recommendation
|
| 2 |
+
|
| 3 |
+
MediPredix
|
| 4 |
+
|
| 5 |
+
Pharmaceutical Sentiment Analysis System" or "PSAS.
|
| 6 |
+
|
| 7 |
+
Pharmaceutical Sentiment Analysis System" or "PSAS.
|
| 8 |
+
|
| 9 |
+
Medication Sentiment Analysis Platform" (MSAP), or "Clinical Review and Drug Assessment Tool" (CRDAT)
|
| 10 |
+
|
| 11 |
+
Medication Intelligence: Predicting Diseases and Recommending Treatments through Drug Review Sentiment Analysis
|
requirements.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
beautifulsoup4==4.11.2
|
| 2 |
+
bokeh==3.0.3
|
| 3 |
+
bs4==0.0.1
|
| 4 |
+
GitPython==3.1.30
|
| 5 |
+
joblib==1.2.0
|
| 6 |
+
nltk==3.8.1
|
| 7 |
+
numpy==1.24.2
|
| 8 |
+
pandas==1.5.3
|
| 9 |
+
regex==2022.10.31
|
| 10 |
+
scikit-learn==1.2.1
|
| 11 |
+
scipy==1.10.0
|
| 12 |
+
SpeechRecognition==1.2.3
|
| 13 |
+
streamlit==1.18.1
|
| 14 |
+
streamlit-bokeh-events==0.1.2
|
| 15 |
+
toml==0.10.2
|
| 16 |
+
tqdm==4.64.1
|
| 17 |
+
|