Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,35 +32,31 @@ def predict_salary(age, education_num, sex, capital_gain, capital_loss, hours_pe
|
|
| 32 |
|
| 33 |
return label, confidence, fig
|
| 34 |
|
|
|
|
|
|
|
| 35 |
with gr.Blocks(css="""
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
.gr-
|
| 40 |
-
.gr-box:hover { transform: scale(1.02); }
|
| 41 |
-
h1, h3, p { color: white; text-align: center; }
|
| 42 |
-
.gr-button { background: linear-gradient(135deg, #1db954, #1ed760) !important; color: white !important; border-radius: 10px; font-size: 1.1em; transition: background 0.3s ease; }
|
| 43 |
-
#predict-button:hover { animation: pulseBtn 1s infinite; }
|
| 44 |
-
@keyframes pulseBtn {
|
| 45 |
-
0% { transform: scale(1); }
|
| 46 |
-
50% { transform: scale(1.05); }
|
| 47 |
-
100% { transform: scale(1); }
|
| 48 |
-
}
|
| 49 |
-
input:hover, select:hover, textarea:hover {
|
| 50 |
-
box-shadow: 0 0 5px #1db954;
|
| 51 |
-
}
|
| 52 |
-
.gr-plot { animation: fadein 1s ease; }
|
| 53 |
-
@keyframes fadein {
|
| 54 |
-
from { opacity: 0; }
|
| 55 |
-
to { opacity: 1; }
|
| 56 |
-
}
|
| 57 |
.gr-radio .gr-form { display: flex; justify-content: center !important; }
|
| 58 |
"""
|
| 59 |
) as demo:
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
gr.Markdown("""
|
| 62 |
<div style='max-width: 700px; margin: 0 auto;'>
|
| 63 |
-
<h1 style=
|
| 64 |
<p style='font-size: 1.2em;'>Predict whether someone earns more than $50K/year using financial and demographic data, with AI explainability via SHAP.</p>
|
| 65 |
</div>
|
| 66 |
""")
|
|
@@ -69,26 +65,21 @@ with gr.Blocks(css="""
|
|
| 69 |
with gr.Column():
|
| 70 |
gr.Markdown("<h3>๐ Age</h3>")
|
| 71 |
age = gr.Slider(minimum=0, maximum=100, step=1, value=35, label="", interactive=True)
|
| 72 |
-
gr.Markdown("<p style='text-align:center;'>Enter age in years</p>")
|
| 73 |
|
| 74 |
gr.Markdown("<h3>๐ Education Level</h3>")
|
| 75 |
education = gr.Dropdown(choices=[str(i) for i in range(1, 17)], value="10", label="", interactive=True)
|
| 76 |
-
gr.Markdown("<p style='text-align:center;'>1 = Preschool, 16 = Doctorate</p>")
|
| 77 |
|
| 78 |
-
gr.Markdown("<h3
|
| 79 |
sex = gr.Radio(choices=["Male", "Female"], value="Male", label="", interactive=True)
|
| 80 |
|
| 81 |
-
gr.Markdown("<h3
|
| 82 |
capital_gain = gr.Number(value=0, label="", interactive=True)
|
| 83 |
-
gr.Markdown("<p style='text-align:center;'>Income from asset sales</p>")
|
| 84 |
|
| 85 |
gr.Markdown("<h3>๐ Capital Loss</h3>")
|
| 86 |
capital_loss = gr.Number(value=0, label="", interactive=True)
|
| 87 |
-
gr.Markdown("<p style='text-align:center;'>Loss from asset disposal</p>")
|
| 88 |
|
| 89 |
-
gr.Markdown("<h3
|
| 90 |
hours_per_week = gr.Number(value=40, label="", interactive=True)
|
| 91 |
-
gr.Markdown("<p style='text-align:center;'>Typical work hours weekly</p>")
|
| 92 |
|
| 93 |
predict_btn = gr.Button("๐ฎ Predict", elem_id="predict-button")
|
| 94 |
|
|
@@ -105,6 +96,6 @@ with gr.Blocks(css="""
|
|
| 105 |
outputs=[result, confidence, shap_plot]
|
| 106 |
)
|
| 107 |
|
| 108 |
-
|
| 109 |
|
| 110 |
|
|
|
|
| 32 |
|
| 33 |
return label, confidence, fig
|
| 34 |
|
| 35 |
+
toggle_theme = gr.State(value="dark")
|
| 36 |
+
|
| 37 |
with gr.Blocks(css="""
|
| 38 |
+
body { background-color: #0a0a23; color: white; }
|
| 39 |
+
.gr-box { background-color: #1a1a3d !important; border-radius: 12px; padding: 20px; }
|
| 40 |
+
h1, h3, p { color: white; text-align: center; font-family: 'Segoe UI', sans-serif; }
|
| 41 |
+
.gr-button { background-color: #1db954 !important; color: white !important; border-radius: 10px; font-size: 1.1em; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
.gr-radio .gr-form { display: flex; justify-content: center !important; }
|
| 43 |
"""
|
| 44 |
) as demo:
|
| 45 |
|
| 46 |
+
def switch_theme(theme_choice):
|
| 47 |
+
if theme_choice == "dark":
|
| 48 |
+
return gr.themes.Base().set(body_background="#0a0a23", body_text_color="white"), "dark"
|
| 49 |
+
else:
|
| 50 |
+
return gr.themes.Default(), "light"
|
| 51 |
+
|
| 52 |
+
with gr.Row():
|
| 53 |
+
theme_toggle = gr.Radio(["dark", "light"], value="dark", label="Theme", interactive=True)
|
| 54 |
+
|
| 55 |
+
theme_toggle.change(switch_theme, inputs=theme_toggle, outputs=[demo.theme, toggle_theme])
|
| 56 |
+
|
| 57 |
gr.Markdown("""
|
| 58 |
<div style='max-width: 700px; margin: 0 auto;'>
|
| 59 |
+
<h1 style='font-size: 2.5em;'>๐ผ Income Prediction App</h1>
|
| 60 |
<p style='font-size: 1.2em;'>Predict whether someone earns more than $50K/year using financial and demographic data, with AI explainability via SHAP.</p>
|
| 61 |
</div>
|
| 62 |
""")
|
|
|
|
| 65 |
with gr.Column():
|
| 66 |
gr.Markdown("<h3>๐ Age</h3>")
|
| 67 |
age = gr.Slider(minimum=0, maximum=100, step=1, value=35, label="", interactive=True)
|
|
|
|
| 68 |
|
| 69 |
gr.Markdown("<h3>๐ Education Level</h3>")
|
| 70 |
education = gr.Dropdown(choices=[str(i) for i in range(1, 17)], value="10", label="", interactive=True)
|
|
|
|
| 71 |
|
| 72 |
+
gr.Markdown("<h3>๐ป Sex</h3>")
|
| 73 |
sex = gr.Radio(choices=["Male", "Female"], value="Male", label="", interactive=True)
|
| 74 |
|
| 75 |
+
gr.Markdown("<h3>๐ Capital Gain</h3>")
|
| 76 |
capital_gain = gr.Number(value=0, label="", interactive=True)
|
|
|
|
| 77 |
|
| 78 |
gr.Markdown("<h3>๐ Capital Loss</h3>")
|
| 79 |
capital_loss = gr.Number(value=0, label="", interactive=True)
|
|
|
|
| 80 |
|
| 81 |
+
gr.Markdown("<h3>๐ Hours per Week</h3>")
|
| 82 |
hours_per_week = gr.Number(value=40, label="", interactive=True)
|
|
|
|
| 83 |
|
| 84 |
predict_btn = gr.Button("๐ฎ Predict", elem_id="predict-button")
|
| 85 |
|
|
|
|
| 96 |
outputs=[result, confidence, shap_plot]
|
| 97 |
)
|
| 98 |
|
| 99 |
+
demo.launch()
|
| 100 |
|
| 101 |
|