Spaces:
Runtime error
Runtime error
Commit
·
bcc1f3f
1
Parent(s):
097b324
gradio app
Browse files
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from collections import OrderedDict
|
| 3 |
+
import numpy as np
|
| 4 |
+
from huggingface_hub import from_pretrained_keras
|
| 5 |
+
|
| 6 |
+
def predict(
|
| 7 |
+
age,workclass,fnlwgt,education,education_num,marital_status,occupation,relationship,
|
| 8 |
+
race,gender,capital_gain,capital_loss,hours_per_week,native_country
|
| 9 |
+
):
|
| 10 |
+
user_data = {}
|
| 11 |
+
user_data['age'] = np.array([age],dtype=np.float32)
|
| 12 |
+
user_data['workclass'] = np.array([f'{workclass}'],dtype="object")
|
| 13 |
+
user_data['fnlwgt'] = np.array([fnlwgt],dtype=np.float32)
|
| 14 |
+
user_data['education'] = np.array([f'{education}'],dtype="object")
|
| 15 |
+
user_data['education_num'] = np.array([education_num],dtype=np.float32)
|
| 16 |
+
user_data['marital_status'] = np.array([f'{marital_status}'],dtype="object")
|
| 17 |
+
user_data['occupation'] = np.array([f'{occupation}'],dtype="object")
|
| 18 |
+
user_data['relationship'] = np.array([f'{relationship}'],dtype="object")
|
| 19 |
+
user_data['race'] = np.array([f'{race}'],dtype="object")
|
| 20 |
+
user_data['gender'] = np.array([f'{gender}'],dtype="object")
|
| 21 |
+
user_data['capital_gain'] = np.array([capital_gain],dtype=np.float32)
|
| 22 |
+
user_data['capital_loss'] = np.array([capital_loss],dtype=np.float32)
|
| 23 |
+
user_data['hours_per_week'] = np.array([hours_per_week],dtype=np.float32)
|
| 24 |
+
user_data['native_country'] = np.array([f'{native_country}'],dtype="object")
|
| 25 |
+
test_user_data = OrderedDict(user_data)
|
| 26 |
+
model = from_pretrained_keras("keras-io/neural-decision-forest")
|
| 27 |
+
pred = model.predict(test_user_data)
|
| 28 |
+
pred = np.argmax(pred,axis=1)
|
| 29 |
+
return f"Outcome: {pred}"
|
| 30 |
+
|
| 31 |
+
work_class_list = [' Self-emp-not-inc', ' Private', ' State-gov', ' Federal-gov',' Local-gov', ' ?', ' Self-emp-inc', ' Without-pay',' Never-worked']
|
| 32 |
+
education_list = [' Bachelors', ' HS-grad', ' 11th', ' Masters', ' 9th',' Some-college', ' Assoc-acdm', ' Assoc-voc', ' 7th-8th',' Doctorate', ' Prof-school', ' 5th-6th', ' 10th', ' 1st-4th',' Preschool', ' 12th']
|
| 33 |
+
martial_list = [' Married-civ-spouse',' Divorced',' Married-spouse-absent',' Never-married',' Separated',' Married-AF-spouse',' Widowed']
|
| 34 |
+
race_list = [' White',' Black',' Asian-Pac-Islander',' Amer-Indian-Eskimo',' Other']
|
| 35 |
+
relation_list = [' Husband',' Not-in-family',' Wife',' Own-child',' Unmarried',' Other-relative']
|
| 36 |
+
occupation_list = [' Exec-managerial',' Handlers-cleaners',' Prof-specialty',' Other-service',' Adm-clerical',' Sales',' Craft-repair',' Transport-moving',' Farming-fishing',' Machine-op-inspct',' Tech-support',' ?',' Protective-serv',' Armed-Forces',' Priv-house-serv']
|
| 37 |
+
countries = [' United-States',' Cuba',' Jamaica',' India',' Mexico',' South',' Puerto-Rico',' Honduras',' England',' Canada',' Germany',' Iran',' Philippines',' Italy',' Poland',' Columbia',' Cambodia',' Thailand',' Ecuador',' Laos',' Taiwan',' Haiti',' Portugal',' Dominican-Republic',' El-Salvador',' France',' Guatemala',' China',' Japan',' Yugoslavia',' Peru',' Outlying-US(Guam-USVI-etc)',' Scotland',' Trinadad&Tobago',' Greece',' Nicaragua',' Vietnam',' Hong',' Ireland',' Hungary',' Holand-Netherlands']
|
| 38 |
+
|
| 39 |
+
demo = gr.Interface(
|
| 40 |
+
predict,
|
| 41 |
+
[
|
| 42 |
+
gr.Slider(12, 85, value=1),
|
| 43 |
+
gr.Dropdown(work_class_list),
|
| 44 |
+
gr.Slider(1260, 12225, value=200),
|
| 45 |
+
gr.Dropdown(education_list),
|
| 46 |
+
gr.Slider(1, 16, value=2),
|
| 47 |
+
gr.Dropdown(martial_list),
|
| 48 |
+
gr.Dropdown(occupation_list),
|
| 49 |
+
gr.Dropdown(relation_list),
|
| 50 |
+
gr.Dropdown(race_list),
|
| 51 |
+
gr.Dropdown([' Male',' Female']),
|
| 52 |
+
gr.Slider(0, 10000, value=100),
|
| 53 |
+
gr.Slider(0, 4500, value=75),
|
| 54 |
+
gr.Slider(1, 100, value=2),
|
| 55 |
+
gr.Dropdown(countries),
|
| 56 |
+
],
|
| 57 |
+
"text",
|
| 58 |
+
examples=
|
| 59 |
+
[
|
| 60 |
+
[35,' Private',5000,' Masters',8,' Divorced',' Tech-support',' Husband',' White',' Male',6000,0,40,' Germany'],
|
| 61 |
+
[27,' Self-emp-inc',2400,' Bachelors',6,' Separated',' Prof-specialty',' Wife',' Amer-Indian-Eskimo',' Female',4000,1050,32,' England'],
|
| 62 |
+
]
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
if __name__ == "__main__":
|
| 66 |
+
demo.launch()
|