Jason commited on
Commit
f6d28a6
1 Parent(s): de72cef

first commit

Browse files
Files changed (2) hide show
  1. app.py +56 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import requests
4
+
5
+ def run():
6
+ with st.form(key='form_parameters'):
7
+ passenger_id = st.number_input('Passenger ID', step=1)
8
+ passenger_class = st.radio('Passenger Class', (1, 2, 3))
9
+ passenger_name = st.text_input('Passenger Name')
10
+ sex = st.radio('Sex', ('male', 'female'))
11
+ age = st.number_input('Age', min_value=0, value=17)
12
+ sibsp = st.number_input('Sibling/Spouse', min_value=0, value=0)
13
+ parch = st.number_input('Parent/Children', min_value=0, value=0)
14
+ ticket_number = st.text_input('Ticket Number')
15
+ fare = st.number_input('Fare', min_value=0, value=10)
16
+ cabin_number = st.text_input('Cabin Number')
17
+ embarked = st.radio('Port of Embarkation', ('C', 'Q', 'S'))
18
+
19
+ submitted = st.form_submit_button('Predict')
20
+
21
+ # Create A New data
22
+ data_inf = {
23
+ 'PassengerId': [passenger_id],
24
+ 'Pclass': [passenger_class],
25
+ 'Name': [passenger_name],
26
+ 'Sex': [sex],
27
+ 'Age': [age],
28
+ 'SibSp': [sibsp],
29
+ 'Parch': [parch],
30
+ 'Ticket': [ticket_number],
31
+ 'Fare': [fare],
32
+ 'Cabin': [cabin_number],
33
+ 'Embarked': [embarked]
34
+ }
35
+
36
+ if submitted:
37
+ # Show Inference DataFrame
38
+ st.dataframe(pd.DataFrame(data_inf))
39
+ print('[DEBUG] Data Inference : \n', data_inf)
40
+
41
+ # Predict
42
+ # URL = "http://192.168.1.4:5001/predict"
43
+ URL = "https://backend-titanic-kidfrom.koyeb.app/predict"
44
+ r = requests.post(URL, json=data_inf)
45
+
46
+ if r.status_code == 200:
47
+ res = r.json()
48
+ st.write('## Prediction : ', res['label_names'][0])
49
+ print('[DEBUG] Result : ', res)
50
+ print('')
51
+ else:
52
+ st.write('Error with status code ', str(r.status_code))
53
+
54
+
55
+ if __name__ == '__main__':
56
+ run()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ pandas