forked from anurag-b72/medicine-recommendation-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
63 lines (40 loc) · 2.08 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import streamlit as st
import pickle
import pandas as pd
## To Add External CSS ##
with open('css/style.css') as f:
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
## Application Backend ##
# To load medicine-dataframe from pickle in the form of dictionary
medicines_dict = pickle.load(open('medicine_dict.pkl','rb'))
medicines = pd.DataFrame(medicines_dict)
# To load similarity-vector-data from pickle in the form of dictionary
similarity = pickle.load(open('similarity.pkl','rb'))
def recommend(medicine):
medicine_index = medicines[medicines['Drug_Name'] == medicine].index[0]
distances = similarity[medicine_index]
medicines_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x: x[1])[1:6]
recommended_medicines = []
for i in medicines_list:
recommended_medicines.append(medicines.iloc[i[0]].Drug_Name)
return recommended_medicines
## Appliaction Frontend ##
# Title of the Application
st.title('Medicine Recommender System')
# Searchbox
selected_medicine_name = st.selectbox(
'Type your medicine name whose alternative is to be recommended',
medicines['Drug_Name'].values)
# Recommendation Program
if st.button('Recommend Medicine'):
recommendations = recommend(selected_medicine_name)
j=1
for i in recommendations:
st.write(j,i) # Recommended-drug-name
# st.write("Click here -> "+" https://www.netmeds.com/catalogsearch/result?q="+i) # Recommnded drug purchase link from netmeds
st.write("Click here -> "+" https://pharmeasy.in/search/all?name="+i) # Recommnded-drug purchase link from pharmeasy
j+=1
## Image load ##
from PIL import Image
image = Image.open('images/medicine-image.jpg')
st.image(image, caption='Recommended Medicines')