omershahar commited on
Commit
cea394f
·
verified ·
1 Parent(s): 7976895

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +120 -0
app.py CHANGED
@@ -145,6 +145,54 @@ print("Loaded Dataset B from Hugging Face")
145
  print("Property inventory rows:", len(B))
146
 
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  # ============================================================
149
  # APPROVED DCN-v2 ARCHITECTURE
150
  # ============================================================
@@ -521,6 +569,59 @@ def derive_budget_level(max_budget_usd):
521
 
522
  return "high"
523
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
524
 
525
  PART4_PROPERTY_FIELDS = [
526
  "id",
@@ -962,6 +1063,12 @@ with gr.Blocks(
962
  .selected-example-copy h2 { color:#262626; font-size:22px; margin:3px 0 8px; }
963
  .selected-example-copy p { color:#555; line-height:1.55; margin:0; }
964
  .selected-example-label { color:#003b95; font-size:11px; font-weight:800; letter-spacing:.1em; }
 
 
 
 
 
 
965
  .match-button { background:#0071c2 !important; border:1px solid #0071c2 !important; border-radius:6px !important; color:white !important; font-size:17px !important; font-weight:700 !important; min-height:50px !important; }
966
  .match-button:hover { background:#005fa3 !important; }
967
  .page-content { max-width:1120px; margin:22px auto 44px; }
@@ -1051,6 +1158,9 @@ with gr.Blocks(
1051
  with gr.Column(elem_classes="selected-example"):
1052
  selected_example_output = gr.HTML(value="")
1053
 
 
 
 
1054
  with gr.Column(elem_classes="page-content"):
1055
  full_output = gr.HTML(value="""
1056
  <div class="no-results"><h2>Ready when you are</h2><p>Enter your investment preferences above, then select <strong>Match Me Up!</strong></p></div>
@@ -1066,6 +1176,11 @@ with gr.Blocks(
1066
  inputs=[max_budget, financing, liquidity, risk, goal],
1067
  outputs=[ranked_state, investor_state, property_state],
1068
  )
 
 
 
 
 
1069
  match_event = match_event.then(
1070
  fn=generate_top_3_explanations,
1071
  inputs=[investor_state, property_state], outputs=generation_state,
@@ -1079,6 +1194,11 @@ with gr.Blocks(
1079
  fn=apply_user_example, inputs=quick_starter,
1080
  outputs=[max_budget, financing, liquidity, risk, goal, ranked_state, investor_state, property_state],
1081
  )
 
 
 
 
 
1082
  quick_event = quick_event.then(
1083
  fn=generate_top_3_explanations,
1084
  inputs=[investor_state, property_state], outputs=generation_state,
 
145
  print("Property inventory rows:", len(B))
146
 
147
 
148
+ # ============================================================
149
+ # LOAD DATASET A FOR REPRESENTATIVE INVESTOR DESCRIPTIONS
150
+ # ============================================================
151
+
152
+ DATASET_A_PATH = hf_hub_download(
153
+ repo_id=DATASET_REPO_ID,
154
+ repo_type="dataset",
155
+ filename="rematch_investor_profiles.csv",
156
+ revision=DATASET_REVISION,
157
+ )
158
+
159
+ A = pd.read_csv(DATASET_A_PATH)
160
+
161
+ required_investor_columns = {
162
+ "investor_id",
163
+ "budget_level",
164
+ "max_budget_usd",
165
+ "financing_willingness",
166
+ "liquidity_importance",
167
+ "risk_profile",
168
+ "primary_goal",
169
+ "investor_description",
170
+ }
171
+
172
+ missing_investor_columns = required_investor_columns - set(A.columns)
173
+
174
+ assert not missing_investor_columns, (
175
+ "Dataset A is missing required columns: "
176
+ + str(sorted(missing_investor_columns))
177
+ )
178
+
179
+ for column in [
180
+ "budget_level",
181
+ "financing_willingness",
182
+ "liquidity_importance",
183
+ "risk_profile",
184
+ "primary_goal",
185
+ ]:
186
+ A[column] = A[column].astype(str).str.strip()
187
+
188
+ A["max_budget_usd"] = pd.to_numeric(
189
+ A["max_budget_usd"],
190
+ errors="coerce",
191
+ )
192
+
193
+ print("Loaded Dataset A from Hugging Face")
194
+ print("Investor profile rows:", len(A))
195
+
196
  # ============================================================
197
  # APPROVED DCN-v2 ARCHITECTURE
198
  # ============================================================
 
569
 
570
  return "high"
571
 
572
+ def render_representative_investor_profile(
573
+ max_budget_usd,
574
+ financing_willingness,
575
+ liquidity_importance,
576
+ risk_profile,
577
+ primary_goal,
578
+ ):
579
+ """Return one deterministic Dataset A description matching the user."""
580
+
581
+ budget_level = derive_budget_level(max_budget_usd)
582
+ budget = float(max_budget_usd)
583
+
584
+ matches = A[
585
+ (A["budget_level"] == budget_level)
586
+ & (A["financing_willingness"] == financing_willingness)
587
+ & (A["liquidity_importance"] == liquidity_importance)
588
+ & (A["risk_profile"] == risk_profile)
589
+ & (A["primary_goal"] == primary_goal)
590
+ & A["max_budget_usd"].notna()
591
+ & A["investor_description"].notna()
592
+ ].copy()
593
+
594
+ if matches.empty:
595
+ return ""
596
+
597
+ matches["budget_distance"] = (
598
+ matches["max_budget_usd"] - budget
599
+ ).abs()
600
+
601
+ selected = matches.sort_values(
602
+ ["budget_distance", "investor_id"],
603
+ ascending=[True, True],
604
+ kind="mergesort",
605
+ ).iloc[0]
606
+
607
+ description = html.escape(
608
+ str(selected["investor_description"]).strip()
609
+ )
610
+
611
+ return f"""
612
+ <div class="representative-profile-card">
613
+ <div class="representative-profile-label">
614
+ YOUR INVESTOR PROFILE
615
+ </div>
616
+ <h2>A profile that matches your selections</h2>
617
+ <p>“{description}”</p>
618
+ <div class="representative-profile-note">
619
+ Representative description selected from the
620
+ LLM-generated synthetic investor profiles in Dataset A.
621
+ </div>
622
+ </div>
623
+ """
624
+
625
 
626
  PART4_PROPERTY_FIELDS = [
627
  "id",
 
1063
  .selected-example-copy h2 { color:#262626; font-size:22px; margin:3px 0 8px; }
1064
  .selected-example-copy p { color:#555; line-height:1.55; margin:0; }
1065
  .selected-example-label { color:#003b95; font-size:11px; font-weight:800; letter-spacing:.1em; }
1066
+ .representative-profile { max-width:1120px; margin:18px auto 0; }
1067
+ .representative-profile-card { background:white; border-left:5px solid var(--blue); border-radius:8px; box-shadow:0 2px 8px rgba(0,0,0,.08); padding:20px 22px; }
1068
+ .representative-profile-label { color:var(--blue); font-size:11px; font-weight:800; letter-spacing:.1em; }
1069
+ .representative-profile-card h2 { color:#262626; font-size:21px; margin:5px 0 10px; }
1070
+ .representative-profile-card p { color:#404040; font-size:16px; font-style:italic; line-height:1.6; margin:0; }
1071
+ .representative-profile-note { color:#777; font-size:11px; margin-top:10px; }
1072
  .match-button { background:#0071c2 !important; border:1px solid #0071c2 !important; border-radius:6px !important; color:white !important; font-size:17px !important; font-weight:700 !important; min-height:50px !important; }
1073
  .match-button:hover { background:#005fa3 !important; }
1074
  .page-content { max-width:1120px; margin:22px auto 44px; }
 
1158
  with gr.Column(elem_classes="selected-example"):
1159
  selected_example_output = gr.HTML(value="")
1160
 
1161
+ with gr.Column(elem_classes="representative-profile"):
1162
+ representative_profile_output = gr.HTML(value="")
1163
+
1164
  with gr.Column(elem_classes="page-content"):
1165
  full_output = gr.HTML(value="""
1166
  <div class="no-results"><h2>Ready when you are</h2><p>Enter your investment preferences above, then select <strong>Match Me Up!</strong></p></div>
 
1176
  inputs=[max_budget, financing, liquidity, risk, goal],
1177
  outputs=[ranked_state, investor_state, property_state],
1178
  )
1179
+ match_event = match_event.then(
1180
+ fn=render_representative_investor_profile,
1181
+ inputs=[max_budget, financing, liquidity, risk, goal],
1182
+ outputs=representative_profile_output,
1183
+ )
1184
  match_event = match_event.then(
1185
  fn=generate_top_3_explanations,
1186
  inputs=[investor_state, property_state], outputs=generation_state,
 
1194
  fn=apply_user_example, inputs=quick_starter,
1195
  outputs=[max_budget, financing, liquidity, risk, goal, ranked_state, investor_state, property_state],
1196
  )
1197
+ quick_event = quick_event.then(
1198
+ fn=render_representative_investor_profile,
1199
+ inputs=[max_budget, financing, liquidity, risk, goal],
1200
+ outputs=representative_profile_output,
1201
+ )
1202
  quick_event = quick_event.then(
1203
  fn=generate_top_3_explanations,
1204
  inputs=[investor_state, property_state], outputs=generation_state,