Spaces:
Runtime error
Runtime error
danupurnomo
commited on
Commit
·
96dca20
1
Parent(s):
8ec06e7
initial commit
Browse files- app.py +55 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = "https://backend-titanic-danu.koyeb.app/predict"
|
43 |
+
r = requests.post(URL, json=data_inf)
|
44 |
+
|
45 |
+
if r.status_code == 200:
|
46 |
+
res = r.json()
|
47 |
+
st.write('## Prediction : ', res['label_names'])
|
48 |
+
print('[DEBUG] Result : ', res)
|
49 |
+
print('')
|
50 |
+
else:
|
51 |
+
st.write('Error with status code ', str(r.status_code))
|
52 |
+
|
53 |
+
|
54 |
+
if __name__ == '__main__':
|
55 |
+
run()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|