Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,24 +4,24 @@ from pytorch_tabular import TabularModel
|
|
4 |
from pytorch_tabular.config import DataConfig, TrainerConfig
|
5 |
from pytorch_tabular.models import CategoryEmbeddingModelConfig
|
6 |
|
7 |
-
# Sample
|
8 |
data = {
|
9 |
-
'
|
10 |
-
'
|
11 |
-
'
|
12 |
-
'
|
13 |
}
|
14 |
df = pd.DataFrame(data)
|
15 |
|
16 |
# Configure pytorch_tabular
|
17 |
data_config = DataConfig(
|
18 |
-
target=["
|
19 |
-
continuous_cols=["
|
20 |
)
|
21 |
|
22 |
model_config = CategoryEmbeddingModelConfig(
|
23 |
task="classification",
|
24 |
-
layers="64-64",
|
25 |
learning_rate=1e-3
|
26 |
)
|
27 |
|
@@ -41,29 +41,28 @@ except ValueError as e:
|
|
41 |
print(f"Error initializing TabularModel: {e}")
|
42 |
|
43 |
# Define Inference Function
|
44 |
-
def classify(
|
45 |
input_data = pd.DataFrame({
|
46 |
-
"
|
47 |
-
"
|
48 |
-
"
|
49 |
})
|
50 |
prediction = tabular_model.predict(input_data)["prediction"].iloc[0]
|
51 |
-
return "
|
52 |
|
53 |
# Gradio Interface
|
54 |
iface = gr.Interface(
|
55 |
fn=classify,
|
56 |
inputs=[
|
57 |
-
gr.Slider(
|
58 |
-
gr.Slider(
|
59 |
-
gr.Slider(
|
60 |
],
|
61 |
outputs="text",
|
62 |
-
title="
|
63 |
-
description="
|
64 |
)
|
65 |
|
66 |
# Launch the Gradio app with necessary server settings
|
67 |
print("Launching Gradio Interface...")
|
68 |
iface.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
69 |
-
|
|
|
4 |
from pytorch_tabular.config import DataConfig, TrainerConfig
|
5 |
from pytorch_tabular.models import CategoryEmbeddingModelConfig
|
6 |
|
7 |
+
# Sample meaningful data for loan approval prediction
|
8 |
data = {
|
9 |
+
'age': [25, 45, 35, 50, 23, 63, 41, 34],
|
10 |
+
'income': [50000, 120000, 75000, 60000, 48000, 150000, 90000, 80000],
|
11 |
+
'credit_score': [650, 720, 680, 690, 640, 780, 710, 660],
|
12 |
+
'approved': [1, 1, 0, 0, 0, 1, 1, 0] # Binary target: 1 for approved, 0 for rejected
|
13 |
}
|
14 |
df = pd.DataFrame(data)
|
15 |
|
16 |
# Configure pytorch_tabular
|
17 |
data_config = DataConfig(
|
18 |
+
target=["approved"],
|
19 |
+
continuous_cols=["age", "income", "credit_score"]
|
20 |
)
|
21 |
|
22 |
model_config = CategoryEmbeddingModelConfig(
|
23 |
task="classification",
|
24 |
+
layers="64-64", # Hidden layer sizes for the model
|
25 |
learning_rate=1e-3
|
26 |
)
|
27 |
|
|
|
41 |
print(f"Error initializing TabularModel: {e}")
|
42 |
|
43 |
# Define Inference Function
|
44 |
+
def classify(age, income, credit_score):
|
45 |
input_data = pd.DataFrame({
|
46 |
+
"age": [age],
|
47 |
+
"income": [income],
|
48 |
+
"credit_score": [credit_score]
|
49 |
})
|
50 |
prediction = tabular_model.predict(input_data)["prediction"].iloc[0]
|
51 |
+
return "Loan Approved" if prediction == 1 else "Loan Rejected"
|
52 |
|
53 |
# Gradio Interface
|
54 |
iface = gr.Interface(
|
55 |
fn=classify,
|
56 |
inputs=[
|
57 |
+
gr.Slider(18, 70, step=1, label="Age"),
|
58 |
+
gr.Slider(30000, 200000, step=5000, label="Annual Income"),
|
59 |
+
gr.Slider(300, 850, step=10, label="Credit Score")
|
60 |
],
|
61 |
outputs="text",
|
62 |
+
title="Loan Approval Prediction",
|
63 |
+
description="Predicts loan approval based on age, income, and credit score."
|
64 |
)
|
65 |
|
66 |
# Launch the Gradio app with necessary server settings
|
67 |
print("Launching Gradio Interface...")
|
68 |
iface.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
|