nisharg nargund commited on
Commit
14ee83f
·
1 Parent(s): d1569a0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import pandas as pd
4
+
5
+ ## To Add External CSS ##
6
+ with open('css/style.css') as f:
7
+ st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
8
+
9
+
10
+
11
+
12
+ ## Application Backend ##
13
+
14
+ # To load medicine-dataframe from pickle in the form of dictionary
15
+ medicines_dict = pickle.load(open('medicine_dict.pkl','rb'))
16
+ medicines = pd.DataFrame(medicines_dict)
17
+
18
+ # To load similarity-vector-data from pickle in the form of dictionary
19
+ similarity = pickle.load(open('similarity.pkl','rb'))
20
+
21
+ def recommend(medicine):
22
+ medicine_index = medicines[medicines['Drug_Name'] == medicine].index[0]
23
+ distances = similarity[medicine_index]
24
+ medicines_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x: x[1])[1:6]
25
+
26
+ recommended_medicines = []
27
+ for i in medicines_list:
28
+ recommended_medicines.append(medicines.iloc[i[0]].Drug_Name)
29
+ return recommended_medicines
30
+
31
+
32
+
33
+
34
+
35
+ ## Appliaction Frontend ##
36
+
37
+ # Title of the Application
38
+ st.title('Medicine Recommender System')
39
+
40
+
41
+
42
+ # Searchbox
43
+ selected_medicine_name = st.selectbox(
44
+ 'Type your medicine name whose alternative is to be recommended',
45
+ medicines['Drug_Name'].values)
46
+
47
+
48
+ # Recommendation Program
49
+ if st.button('Recommend Medicine'):
50
+ recommendations = recommend(selected_medicine_name)
51
+ j=1
52
+ for i in recommendations:
53
+ st.write(j,i) # Recommended-drug-name
54
+
55
+
56
+
57
+
58
+
59
+ ## Image load ##
60
+ from PIL import Image
61
+ #image = Image.open('images/medicine-image.jpg')
62
+ #st.image(image, caption='Recommended Medicines')
63
+
64
+