Nadeem005 commited on
Commit
7182344
·
verified ·
1 Parent(s): aa387d7

Update app.py

Browse files

upload app script

Files changed (1) hide show
  1. app.py +29 -42
app.py CHANGED
@@ -6,7 +6,7 @@ import joblib
6
  model = joblib.load('heart_disease_model.joblib')
7
  model_columns = joblib.load('model_columns.joblib')
8
 
9
- # --- 2. Define the Prediction Function ---
10
  def predict_heart_disease(age, sex, cp, restbp, chol, thalach, exang, ca, thal):
11
  input_data = {
12
  'age': age, 'sex': sex, 'cp': cp, 'restbp': restbp, 'chol': chol,
@@ -35,61 +35,46 @@ def predict_heart_disease(age, sex, cp, restbp, chol, thalach, exang, ca, thal):
35
 
36
  return f"{result_text}<br><div style='margin-top: 10px; color: #a1a1aa;'>Confidence: {confidence*100:.2f}%</div>"
37
 
38
- # --- 3. Custom CSS for Advanced Styling ---
39
  custom_css = """
40
  body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
41
  .gradio-container { background-color: #1f2937; border-radius: 15px !important; }
42
 
43
- /* --- Input component labels (e.g., "Age", "Sex") --- */
44
- /* <<< THIS IS THE CORRECTED AND MORE SPECIFIC SELECTOR FOR THE LABELS --- */
45
- .gradio-form > div > .label {
46
- color: #f97316 !important; /* Orange color for feature labels */
47
- font-weight: bold !important;
48
- font-size: 1.1em !important;
49
- }
50
-
51
- /* --- The selectable numbers/options (Radio Buttons) --- */
52
- .gradio-radio-button {
53
- background-color: #374151;
54
- color: #d1d5db;
55
- border: 1px solid #4b5563;
56
- }
57
- .gradio-radio-button.selected {
58
- background-color: #34d399 !important;
59
- color: white !important;
60
- border-color: #34d399 !important;
61
- }
62
 
63
- /* --- Slider Color --- */
64
- .gradio-slider-track-color {
65
- background-color: #60a5fa !important;
66
- }
67
 
68
- /* --- Button Alignment and Interactivity --- */
69
  #buttons-row { display: flex; gap: 10px; justify-content: center; width: 100%; }
70
  #buttons-row > button { flex-grow: 1; }
71
  .gradio-button { transition: all 0.2s ease-in-out !important; transform: scale(1.0); }
72
  .gradio-button:hover { transform: scale(1.03); filter: brightness(1.1); }
73
  .gradio-button:active { transform: scale(0.98); }
74
 
75
- /* --- Permanent Result Box Styling --- */
76
  #result-box {
77
- background-color: #374151;
78
- border: 1px solid #4b5563;
79
- padding: 20px;
80
- border-radius: 10px;
81
- text-align: center;
82
- min-height: 120px;
83
- display: flex;
84
- align-items: center;
85
- justify-content: center;
86
- flex-direction: column;
87
- color: #e5e7eb;
88
  }
89
  """
90
 
91
- # --- 4. Build the UI with Gradio Blocks for full control ---
92
- with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
 
 
 
 
 
 
 
 
 
 
93
  gr.Markdown("# ❤️ CardioCompass: Heart Disease Predictor")
94
  gr.Markdown("Enter patient details to predict the likelihood of having heart disease.")
95
 
@@ -111,14 +96,16 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
111
  clear_button = gr.ClearButton(value="Clear")
112
  submit_button = gr.Button("Submit", variant="primary")
113
 
114
- # --- 5. Connect the components ---
115
  inputs_list = [age_in, sex_in, cp_in, restbp_in, chol_in, thalach_in, exang_in, ca_in, thal_in]
116
  submit_button.click(fn=predict_heart_disease, inputs=inputs_list, outputs=result_out)
117
  clear_button.add(inputs_list)
118
 
119
- # --- 6. Launch the App ---
120
  demo.launch(share=True)
121
 
 
 
122
 
123
 
124
 
 
6
  model = joblib.load('heart_disease_model.joblib')
7
  model_columns = joblib.load('model_columns.joblib')
8
 
9
+ # --- 2. Define the Prediction Function (No changes here) ---
10
  def predict_heart_disease(age, sex, cp, restbp, chol, thalach, exang, ca, thal):
11
  input_data = {
12
  'age': age, 'sex': sex, 'cp': cp, 'restbp': restbp, 'chol': chol,
 
35
 
36
  return f"{result_text}<br><div style='margin-top: 10px; color: #a1a1aa;'>Confidence: {confidence*100:.2f}%</div>"
37
 
38
+ # --- 3. Custom CSS for General Styling (Label color rule removed) ---
39
  custom_css = """
40
  body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
41
  .gradio-container { background-color: #1f2937; border-radius: 15px !important; }
42
 
43
+ /* The selectable numbers/options (Radio Buttons) */
44
+ .gradio-radio-button { background-color: #374151; color: #d1d5db; border: 1px solid #4b5563; }
45
+ .gradio-radio-button.selected { background-color: #34d399 !important; color: white !important; border-color: #34d399 !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
+ /* Slider Color */
48
+ .gradio-slider-track-color { background-color: #60a5fa !important; }
 
 
49
 
50
+ /* Button Alignment and Interactivity */
51
  #buttons-row { display: flex; gap: 10px; justify-content: center; width: 100%; }
52
  #buttons-row > button { flex-grow: 1; }
53
  .gradio-button { transition: all 0.2s ease-in-out !important; transform: scale(1.0); }
54
  .gradio-button:hover { transform: scale(1.03); filter: brightness(1.1); }
55
  .gradio-button:active { transform: scale(0.98); }
56
 
57
+ /* Permanent Result Box Styling */
58
  #result-box {
59
+ background-color: #374151; border: 1px solid #4b5563; padding: 20px;
60
+ border-radius: 10px; text-align: center; min-height: 120px;
61
+ display: flex; align-items: center; justify-content: center;
62
+ flex-direction: column; color: #e5e7eb;
 
 
 
 
 
 
 
63
  }
64
  """
65
 
66
+ # --- 4. Define the Custom Theme with the Orange Label Color ---
67
+ # This is the new, more reliable way to set the color.
68
+ theme = gr.themes.Soft(
69
+ primary_hue="rose" # This sets the main accent color
70
+ ).set(
71
+ block_label_text_color_dark="#f97316", # Orange color for labels in dark mode
72
+ block_label_text_color="#f97316" # Orange color for labels in light mode
73
+ )
74
+
75
+
76
+ # --- 5. Build the UI with Gradio Blocks ---
77
+ with gr.Blocks(theme=theme, css=custom_css) as demo: # We pass our new theme object here
78
  gr.Markdown("# ❤️ CardioCompass: Heart Disease Predictor")
79
  gr.Markdown("Enter patient details to predict the likelihood of having heart disease.")
80
 
 
96
  clear_button = gr.ClearButton(value="Clear")
97
  submit_button = gr.Button("Submit", variant="primary")
98
 
99
+ # --- 6. Connect the components ---
100
  inputs_list = [age_in, sex_in, cp_in, restbp_in, chol_in, thalach_in, exang_in, ca_in, thal_in]
101
  submit_button.click(fn=predict_heart_disease, inputs=inputs_list, outputs=result_out)
102
  clear_button.add(inputs_list)
103
 
104
+ # --- 7. Launch the App ---
105
  demo.launch(share=True)
106
 
107
+
108
+
109
 
110
 
111