Spaces:
Runtime error
Runtime error
Commit
·
a763ea9
1
Parent(s):
efa9908
adsf
Browse files
app.py
CHANGED
@@ -47,7 +47,26 @@ model = mr.get_model("titanic_modal", version=3)
|
|
47 |
model_dir = model.download()
|
48 |
model = joblib.load(model_dir + "/titanic_model.pkl")
|
49 |
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
# features = pd.read_csv(
|
52 |
# "https://raw.githubusercontent.com/Nathanotal/remoteFiles/main/titanicCleaned.csv")
|
53 |
# features = features.drop(columns=["survived"])
|
@@ -65,7 +84,8 @@ columnHeaders = ["Pclass", "Sex", "Age", "SibSp",
|
|
65 |
|
66 |
|
67 |
def titanic(Pclass, Sex, Age, SibSp, Parch, Fare, Embarked):
|
68 |
-
|
|
|
69 |
# Create a dataframe from the input values
|
70 |
input_variables = pd.DataFrame(
|
71 |
[[Pclass, Sex, Age, SibSp, Parch, Fare, Embarked, 1.0]], columns=columnHeaders)
|
@@ -109,25 +129,35 @@ def titanic(Pclass, Sex, Age, SibSp, Parch, Fare, Embarked):
|
|
109 |
return img, img2
|
110 |
|
111 |
|
112 |
-
catToInput = {
|
113 |
-
"Sex": ["male", "female"],
|
114 |
-
"Embarked": ["S", "C", "Q"],
|
115 |
-
"Pclass": [0, 1, 2]
|
116 |
-
}
|
117 |
-
|
118 |
-
|
119 |
featureLabels = ["Pclass", "Name", "Sex", "Age", "SibSp",
|
120 |
"Parch", "Ticket", "Fare", "Cabin", "Embarked"]
|
121 |
-
|
122 |
for feature in featureLabels:
|
123 |
if feature in numericalInputs:
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
elif feature in worthlessInputs:
|
126 |
pass
|
127 |
# inputs.append(gr.Inputs.Textbox(default='text', label=feature))
|
128 |
elif feature in categoricalInputs:
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
else:
|
132 |
raise Exception(f'Feature: "{feature}" not found')
|
133 |
|
|
|
47 |
model_dir = model.download()
|
48 |
model = joblib.load(model_dir + "/titanic_model.pkl")
|
49 |
|
50 |
+
|
51 |
+
catToInput = {
|
52 |
+
"Sex": ["male", "female"],
|
53 |
+
"Embarked": ["Southampton", "Cherbourg", "Queenstown"],
|
54 |
+
"Pclass": ["First", "Second", "Thrid"]
|
55 |
+
}
|
56 |
+
|
57 |
+
cityToInput = {
|
58 |
+
"Southampton": "S",
|
59 |
+
"Cherbourg": "C",
|
60 |
+
"Queenstown": "Q"
|
61 |
+
}
|
62 |
+
|
63 |
+
classToInput = {
|
64 |
+
"First": 1,
|
65 |
+
"Second": 2,
|
66 |
+
"Third": 3
|
67 |
+
}
|
68 |
+
|
69 |
+
|
70 |
# features = pd.read_csv(
|
71 |
# "https://raw.githubusercontent.com/Nathanotal/remoteFiles/main/titanicCleaned.csv")
|
72 |
# features = features.drop(columns=["survived"])
|
|
|
84 |
|
85 |
|
86 |
def titanic(Pclass, Sex, Age, SibSp, Parch, Fare, Embarked):
|
87 |
+
Embarked = cityToInput[Embarked]
|
88 |
+
Pclass = classToInput[Pclass]
|
89 |
# Create a dataframe from the input values
|
90 |
input_variables = pd.DataFrame(
|
91 |
[[Pclass, Sex, Age, SibSp, Parch, Fare, Embarked, 1.0]], columns=columnHeaders)
|
|
|
129 |
return img, img2
|
130 |
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
featureLabels = ["Pclass", "Name", "Sex", "Age", "SibSp",
|
133 |
"Parch", "Ticket", "Fare", "Cabin", "Embarked"]
|
|
|
134 |
for feature in featureLabels:
|
135 |
if feature in numericalInputs:
|
136 |
+
if feature == 'Age':
|
137 |
+
inputs.append(gr.inputs.Number(9, 75, 1, label='Age (years)'))
|
138 |
+
if feature == 'SibSp':
|
139 |
+
inputs.append(gr.inputs.Number(
|
140 |
+
0, 10, 1, label='Number of siblings/spouses aboard'))
|
141 |
+
if feature == 'Parch':
|
142 |
+
inputs.append(gr.inputs.Number(
|
143 |
+
0, 10, 1, label='Number of parents/children aboard'))
|
144 |
+
if feature == 'Fare':
|
145 |
+
inputs.append(gr.inputs.Number(0, 1000, 1, label='Ticket fare'))
|
146 |
+
else:
|
147 |
+
raise Exception(f'Feature: "{feature}" not found')
|
148 |
elif feature in worthlessInputs:
|
149 |
pass
|
150 |
# inputs.append(gr.Inputs.Textbox(default='text', label=feature))
|
151 |
elif feature in categoricalInputs:
|
152 |
+
if feature == "Sex":
|
153 |
+
inputs.append(gr.inputs.Dropdown(
|
154 |
+
choices=catToInput.get(feature), default="male", label=feature))
|
155 |
+
if feature == "Embarked":
|
156 |
+
inputs.append(gr.inputs.Dropdown(
|
157 |
+
choices=catToInput.get(feature), default="Southampton", label='City of embarkation'))
|
158 |
+
if feature == "Pclass":
|
159 |
+
inputs.append(gr.inputs.Dropdown(
|
160 |
+
choices=catToInput.get(feature), default=3, label='Ticket class'))
|
161 |
else:
|
162 |
raise Exception(f'Feature: "{feature}" not found')
|
163 |
|