Ric commited on
Commit
42c0b67
·
1 Parent(s): b6f148b

Style prediction card and button

Browse files
Files changed (1) hide show
  1. app.py +71 -6
app.py CHANGED
@@ -31,6 +31,49 @@ from sklearn.model_selection import train_test_split
31
  from sklearn.tree import DecisionTreeClassifier, plot_tree
32
 
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  def build_dataset(n_samples: int = 200, seed: int = 42) -> pd.DataFrame:
35
  rng = np.random.default_rng(seed)
36
  data = pd.DataFrame(
@@ -182,14 +225,33 @@ def predict_study_location(
182
  top_index = probabilities.argmax()
183
  label = MODEL.classes_[top_index]
184
  confidence = probabilities[top_index]
 
 
 
 
 
 
 
185
  steps = describe_path(MODEL, sample)
186
  report_lines = "\n".join(f"- {step}" for step in steps)
187
- prediction_text = f"### Recommended Study Location: **{label}**"
188
- confidence_text = f"Confidence: `{confidence:.1%}` | Secondary: `{probabilities[1 - top_index]:.1%}`"
189
- return prediction_text, confidence_text, report_lines
 
 
 
 
 
 
 
 
 
190
 
191
 
192
- with gr.Blocks(title="UNLV Study Location Predictor") as demo:
 
 
 
193
  gr.Markdown(
194
  """
195
  # UNLV Study Location Predictor
@@ -234,10 +296,13 @@ with gr.Blocks(title="UNLV Study Location Predictor") as demo:
234
  label="Is it the weekend?",
235
  value=False,
236
  )
237
- run_button = gr.Button("Predict Study Location")
 
 
 
238
 
239
  with gr.Column():
240
- prediction_box = gr.Markdown()
241
  confidence_box = gr.Markdown()
242
  rationale_box = gr.Markdown()
243
 
 
31
  from sklearn.tree import DecisionTreeClassifier, plot_tree
32
 
33
 
34
+ CUSTOM_CSS = """
35
+ #predict-button {
36
+ background: linear-gradient(135deg, #ce1126, #8b0000);
37
+ color: white;
38
+ font-weight: 700;
39
+ font-size: 1.05rem;
40
+ border: none;
41
+ box-shadow: 0 6px 18px rgba(139, 0, 0, 0.35);
42
+ }
43
+ #predict-button:hover {
44
+ transform: translateY(-1px);
45
+ box-shadow: 0 10px 24px rgba(139, 0, 0, 0.45);
46
+ }
47
+ .prediction-card {
48
+ border: 3px solid #ce1126;
49
+ border-radius: 18px;
50
+ padding: 1.5rem;
51
+ background: #fff4f4;
52
+ text-align: center;
53
+ box-shadow: 0 12px 30px rgba(206, 17, 38, 0.15);
54
+ }
55
+ .prediction-card .location {
56
+ font-size: 2rem;
57
+ font-weight: 800;
58
+ color: #7b0011;
59
+ letter-spacing: 0.5px;
60
+ }
61
+ .prediction-card .location span {
62
+ text-transform: uppercase;
63
+ }
64
+ .prediction-card .confidence {
65
+ margin-top: 0.75rem;
66
+ font-size: 1.05rem;
67
+ color: #333;
68
+ }
69
+ .prediction-card .secondary {
70
+ margin-top: 0.25rem;
71
+ font-size: 0.95rem;
72
+ color: #555;
73
+ }
74
+ """
75
+
76
+
77
  def build_dataset(n_samples: int = 200, seed: int = 42) -> pd.DataFrame:
78
  rng = np.random.default_rng(seed)
79
  data = pd.DataFrame(
 
225
  top_index = probabilities.argmax()
226
  label = MODEL.classes_[top_index]
227
  confidence = probabilities[top_index]
228
+ secondary_index = (
229
+ probabilities.argsort()[::-1][1]
230
+ if len(probabilities) > 1
231
+ else top_index
232
+ )
233
+ secondary_confidence = probabilities[secondary_index]
234
+ secondary_label = MODEL.classes_[secondary_index]
235
  steps = describe_path(MODEL, sample)
236
  report_lines = "\n".join(f"- {step}" for step in steps)
237
+ prediction_html = f"""
238
+ <div class="prediction-card">
239
+ <div class="location">Study at the <span>{label}</span></div>
240
+ <div class="confidence">Confidence: {confidence:.1%}</div>
241
+ <div class="secondary">Next best: {secondary_label} ({secondary_confidence:.1%})</div>
242
+ </div>
243
+ """.strip()
244
+ confidence_text = (
245
+ f"Primary recommendation: **{label}** (`{confidence:.1%}`) · "
246
+ f"Alternate: **{secondary_label}** (`{secondary_confidence:.1%}`)"
247
+ )
248
+ return prediction_html, confidence_text, report_lines
249
 
250
 
251
+ with gr.Blocks(
252
+ title="UNLV Study Location Predictor",
253
+ css=CUSTOM_CSS,
254
+ ) as demo:
255
  gr.Markdown(
256
  """
257
  # UNLV Study Location Predictor
 
296
  label="Is it the weekend?",
297
  value=False,
298
  )
299
+ run_button = gr.Button(
300
+ "Predict Study Location",
301
+ elem_id="predict-button",
302
+ )
303
 
304
  with gr.Column():
305
+ prediction_box = gr.HTML()
306
  confidence_box = gr.Markdown()
307
  rationale_box = gr.Markdown()
308