WSYAM806 commited on
Commit
59234c3
·
1 Parent(s): c5dfd2e

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -32
app.py CHANGED
@@ -1,63 +1,71 @@
1
  import streamlit as st
2
  import pandas as pd
3
- import joblib
 
 
 
 
 
4
 
5
- st.title('FTDS Model Deployment')
6
- st.write("""
7
- Created by FTDS Curriculum Team
 
8
 
9
  Use the sidebar to select input features.
10
  """)
11
 
12
- @st.cache
13
  def fetch_data():
14
- df = pd.read_csv('https://raw.githubusercontent.com/ardhiraka/PFDS_sources/master/campus.csv')
 
 
 
 
 
 
15
  return df
16
 
17
  df = fetch_data()
18
 
19
- gender = st.selectbox('Gender', df['gender'].unique())
20
- ssc = st.number_input('Secondary School Points', value=67.00)
21
- hsc = st.number_input('High School Points', 0.0, value=91.0)
22
- hsc_s = st.selectbox('High School Spec', df['hsc_s'].unique())
23
- degree_p = st.number_input('Degree Points', 0.0, value=58.0)
24
- degree_t = st.selectbox('Degree Spec', df['degree_t'].unique())
25
- workex = st.selectbox('Work Experience?', df['workex'].unique())
26
- etest_p = st.number_input('Etest Points', 0.0, value=78.00)
27
- spec = st.selectbox('Specialization', df['specialisation'].unique())
28
- mba_p = st.number_input('MBA Points', 0.0, value=54.55)
29
 
30
  data = {
31
- 'gender': gender,
32
- 'ssc_p': ssc,
33
- 'hsc_p': hsc,
34
- 'hsc_s': hsc_s,
35
- 'degree_p': degree_p,
36
- 'degree_t': degree_t,
37
- 'workex': workex,
38
- 'etest_p': etest_p,
39
- 'specialisation':spec,
40
- 'mba_p': mba_p
41
  }
42
  input = pd.DataFrame(data, index=[0])
43
 
44
  st.subheader('User Input')
45
  st.write(input)
46
 
47
- load_model = joblib.load("my_model.pkl")
 
 
48
 
49
  if st.button('Predict'):
50
  prediction = load_model.predict(input)
51
 
52
  if prediction == 1:
53
- prediction = 'Placed'
54
  else:
55
- prediction = 'Not Placed'
56
 
57
  st.write('Based on user input, the placement model predicted: ')
58
  st.write(prediction)
59
 
60
- from PIL import Image
61
- image = Image.open('pngtree-2-thumb-up-jempol-oke-mantap-png-image_5287320.png')
 
 
62
 
63
- st.image(image, caption='mantap')
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import pickle
4
+ from sklearn.impute import SimpleImputer
5
+ from sklearn.preprocessing import StandardScaler, MinMaxScaler, OneHotEncoder, OrdinalEncoder
6
+ from sklearn.pipeline import Pipeline
7
+ from sklearn.compose import ColumnTransformer
8
+ from sklearn.ensemble import RandomForestClassifier
9
 
10
+
11
+ st.sidebar.title('Grade Challange 3')
12
+ st.sidebar.write("""
13
+ Created by Wawan Setiawan S
14
 
15
  Use the sidebar to select input features.
16
  """)
17
 
18
+ @st.cache_resource
19
  def fetch_data():
20
+ df = pd.read_csv('h8dsft_P1G3_Wawan_Setiawan.csv')
21
+ df['anaemia'] = df['anaemia'].replace({0: 'no', 1 : 'yes'})
22
+ df['diabetes'] = df['diabetes'].replace({0 : 'no', 1: 'yes'})
23
+ df['high_blood_pressure'] = df['high_blood_pressure'].replace({0 : 'no', 1: 'yes'})
24
+ df['smoking'] = df['smoking'].replace({0 : 'no', 1: 'yes'})
25
+ df['sex'] = df['sex'].replace({0 : 'female', 1: 'male'})
26
+ df['DEATH_EVENT'] = df['DEATH_EVENT'].astype(float)
27
  return df
28
 
29
  df = fetch_data()
30
 
31
+
32
+ creatinine_phosphokinase = st.sidebar.slider('creatinine_phosphokinase', 30,8000)
33
+ serum_creatinine = st.sidebar.slider('serum_creatinine', 0.0,10.0)
34
+ serum_sodium = st.sidebar.slider('serum_sodium', 100., 150.)
35
+ age = st.sidebar.slider('age', 1,100)
36
+ time = st.sidebar.slider('time', 1.0, 300.0)
37
+
 
 
 
38
 
39
  data = {
40
+ 'creatinine_phosphokinase': creatinine_phosphokinase,
41
+ 'serum_creatinine': serum_creatinine,
42
+ 'serum_sodium': serum_sodium,
43
+ 'age': age,
44
+ 'time': time,
45
+
 
 
 
 
46
  }
47
  input = pd.DataFrame(data, index=[0])
48
 
49
  st.subheader('User Input')
50
  st.write(input)
51
 
52
+ load_model = pickle.load(open('all_process.pkl','rb'))
53
+ gaussian_columns_cleaned = pickle.load(open('gaussian_columns_cleaned.txt','rb'))
54
+ iqr_columns_1_cleaned = pickle.load(open('iqr_columns_1_cleaned.txt','rb'))
55
 
56
  if st.button('Predict'):
57
  prediction = load_model.predict(input)
58
 
59
  if prediction == 1:
60
+ prediction = 'Yes'
61
  else:
62
+ prediction = 'No'
63
 
64
  st.write('Based on user input, the placement model predicted: ')
65
  st.write(prediction)
66
 
67
+ chart_data = pd.DataFrame(
68
+ data)
69
+
70
+ st.line_chart(chart_data)
71