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
|
|
|
|
|
| 1 |
+
# ui/intake/choices.py
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
from functools import lru_cache
|
| 5 |
+
|
| 6 |
+
FALLBACK_COUNTRIES = [
|
| 7 |
+
"Australia",
|
| 8 |
+
"Brazil",
|
| 9 |
+
"Canada",
|
| 10 |
+
"China",
|
| 11 |
+
"France",
|
| 12 |
+
"Germany",
|
| 13 |
+
"Hong Kong",
|
| 14 |
+
"India",
|
| 15 |
+
"Indonesia",
|
| 16 |
+
"Ireland",
|
| 17 |
+
"Italy",
|
| 18 |
+
"Japan",
|
| 19 |
+
"Malaysia",
|
| 20 |
+
"Mexico",
|
| 21 |
+
"Netherlands",
|
| 22 |
+
"New Zealand",
|
| 23 |
+
"Nigeria",
|
| 24 |
+
"Philippines",
|
| 25 |
+
"Poland",
|
| 26 |
+
"Portugal",
|
| 27 |
+
"Singapore",
|
| 28 |
+
"South Africa",
|
| 29 |
+
"South Korea",
|
| 30 |
+
"Spain",
|
| 31 |
+
"Sweden",
|
| 32 |
+
"Switzerland",
|
| 33 |
+
"Taiwan",
|
| 34 |
+
"Thailand",
|
| 35 |
+
"United Arab Emirates",
|
| 36 |
+
"United Kingdom",
|
| 37 |
+
"United States",
|
| 38 |
+
"Vietnam",
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
EDUCATION_CHOICES = [
|
| 42 |
+
"High school / secondary",
|
| 43 |
+
"Associate degree",
|
| 44 |
+
"Bachelor's degree",
|
| 45 |
+
"Master's degree",
|
| 46 |
+
"PhD / doctorate",
|
| 47 |
+
"Professional degree (MD, JD, etc.)",
|
| 48 |
+
"Vocational / trade certificate",
|
| 49 |
+
"Currently studying",
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
OCCUPATION_CHOICES = [
|
| 53 |
+
"Software / IT",
|
| 54 |
+
"Engineering (non-software)",
|
| 55 |
+
"Healthcare",
|
| 56 |
+
"Education / teaching",
|
| 57 |
+
"Finance / accounting",
|
| 58 |
+
"Sales / marketing",
|
| 59 |
+
"Design / creative",
|
| 60 |
+
"Trades / skilled labor",
|
| 61 |
+
"Management / executive",
|
| 62 |
+
"Research / academia",
|
| 63 |
+
"Student / no full-time work",
|
| 64 |
+
"Self-employed / freelancer",
|
| 65 |
+
]
|
| 66 |
+
|
| 67 |
+
EXPERIENCE_CHOICES = [
|
| 68 |
+
"Less than 1 year",
|
| 69 |
+
"1-3 years",
|
| 70 |
+
"3-5 years",
|
| 71 |
+
"5-10 years",
|
| 72 |
+
"10+ years",
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
LANGUAGE_CHOICES = [
|
| 76 |
+
"Arabic",
|
| 77 |
+
"Bengali",
|
| 78 |
+
"Dutch",
|
| 79 |
+
"English",
|
| 80 |
+
"French",
|
| 81 |
+
"German",
|
| 82 |
+
"Hindi",
|
| 83 |
+
"Indonesian",
|
| 84 |
+
"Italian",
|
| 85 |
+
"Japanese",
|
| 86 |
+
"Korean",
|
| 87 |
+
"Mandarin Chinese",
|
| 88 |
+
"Polish",
|
| 89 |
+
"Portuguese",
|
| 90 |
+
"Russian",
|
| 91 |
+
"Spanish",
|
| 92 |
+
"Tagalog",
|
| 93 |
+
"Thai",
|
| 94 |
+
"Turkish",
|
| 95 |
+
"Urdu",
|
| 96 |
+
"Vietnamese",
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
BUDGET_CHOICES = [
|
| 100 |
+
"Under USD 5,000 savings",
|
| 101 |
+
"USD 5,000-15,000 savings",
|
| 102 |
+
"USD 15,000-30,000 savings",
|
| 103 |
+
"USD 30,000-50,000 savings",
|
| 104 |
+
"USD 50,000+ savings",
|
| 105 |
+
"Monthly income under USD 2,000",
|
| 106 |
+
"Monthly income USD 2,000-5,000",
|
| 107 |
+
"Monthly income USD 5,000+",
|
| 108 |
+
"Prefer lower cost of living",
|
| 109 |
+
"Flexible / not sure",
|
| 110 |
+
]
|
| 111 |
+
|
| 112 |
+
FAMILY_CHOICES = [
|
| 113 |
+
"Solo applicant",
|
| 114 |
+
"Spouse / partner only",
|
| 115 |
+
"Spouse + 1 child",
|
| 116 |
+
"Spouse + 2+ children",
|
| 117 |
+
"Dependents only (no spouse)",
|
| 118 |
+
"Extended family relocating together",
|
| 119 |
+
]
|
| 120 |
+
|
| 121 |
+
TIMELINE_CHOICES = [
|
| 122 |
+
"ASAP (under 6 months)",
|
| 123 |
+
"6-12 months",
|
| 124 |
+
"12-18 months",
|
| 125 |
+
"2-3 years",
|
| 126 |
+
"Long term / flexible",
|
| 127 |
+
"Exploring options only",
|
| 128 |
+
]
|
| 129 |
+
|
| 130 |
+
RESIDENCE_STATUS_CHOICES = [
|
| 131 |
+
"Citizen",
|
| 132 |
+
"Permanent resident",
|
| 133 |
+
"Work visa / employment pass",
|
| 134 |
+
"Student visa",
|
| 135 |
+
"Dependent / family visa",
|
| 136 |
+
"Tourist / short-term stay",
|
| 137 |
+
"Between visas / relocating soon",
|
| 138 |
+
]
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
@lru_cache(maxsize=1)
|
| 142 |
+
def country_choices() -> list[str]:
|
| 143 |
+
try:
|
| 144 |
+
from apis.rest_countries import _country_index
|
| 145 |
+
|
| 146 |
+
return sorted(
|
| 147 |
+
entry["name"] for entry in _country_index()["iso2"].values()
|
| 148 |
+
)
|
| 149 |
+
except Exception:
|
| 150 |
+
return list(FALLBACK_COUNTRIES)
|
ui/intake/panel.py
CHANGED
|
@@ -1,46 +1,88 @@
|
|
| 1 |
# ui/intake/panel.py
|
| 2 |
import gradio as gr
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from ui.intake.prompts import build_profile_prompt
|
| 5 |
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def render_intake_panel(chat_input: gr.MultimodalTextbox) -> None:
|
|
|
|
|
|
|
| 8 |
with gr.Column(elem_classes=["borderless-form-panel"]):
|
| 9 |
with gr.Row():
|
| 10 |
-
citizenship =
|
| 11 |
label="Citizenship / passports",
|
| 12 |
-
|
|
|
|
| 13 |
)
|
| 14 |
-
|
| 15 |
-
label="Current
|
| 16 |
-
|
| 17 |
)
|
| 18 |
with gr.Row():
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
label="Education",
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
)
|
| 23 |
-
|
| 24 |
-
label="
|
| 25 |
-
|
| 26 |
)
|
| 27 |
with gr.Row():
|
| 28 |
-
languages =
|
| 29 |
label="Languages",
|
| 30 |
-
|
|
|
|
| 31 |
)
|
| 32 |
-
budget =
|
| 33 |
label="Budget",
|
| 34 |
-
|
| 35 |
)
|
| 36 |
with gr.Row():
|
| 37 |
-
family =
|
| 38 |
label="Family / dependents",
|
| 39 |
-
|
| 40 |
)
|
| 41 |
-
timeline =
|
| 42 |
label="Target timeline",
|
| 43 |
-
|
| 44 |
)
|
| 45 |
goals = gr.Textbox(
|
| 46 |
label="Goals in everyday language",
|
|
@@ -54,9 +96,11 @@ def render_intake_panel(chat_input: gr.MultimodalTextbox) -> None:
|
|
| 54 |
fn=build_profile_prompt,
|
| 55 |
inputs=[
|
| 56 |
citizenship,
|
| 57 |
-
|
|
|
|
| 58 |
education,
|
| 59 |
-
|
|
|
|
| 60 |
languages,
|
| 61 |
budget,
|
| 62 |
family,
|
|
|
|
| 1 |
# ui/intake/panel.py
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
from ui.intake.choices import (
|
| 5 |
+
BUDGET_CHOICES,
|
| 6 |
+
EDUCATION_CHOICES,
|
| 7 |
+
EXPERIENCE_CHOICES,
|
| 8 |
+
FAMILY_CHOICES,
|
| 9 |
+
LANGUAGE_CHOICES,
|
| 10 |
+
OCCUPATION_CHOICES,
|
| 11 |
+
RESIDENCE_STATUS_CHOICES,
|
| 12 |
+
TIMELINE_CHOICES,
|
| 13 |
+
country_choices,
|
| 14 |
+
)
|
| 15 |
from ui.intake.prompts import build_profile_prompt
|
| 16 |
|
| 17 |
|
| 18 |
+
def _searchable_dropdown(
|
| 19 |
+
*,
|
| 20 |
+
label: str,
|
| 21 |
+
choices: list[str],
|
| 22 |
+
multiselect: bool = False,
|
| 23 |
+
info: str | None = None,
|
| 24 |
+
) -> gr.Dropdown:
|
| 25 |
+
return gr.Dropdown(
|
| 26 |
+
label=label,
|
| 27 |
+
choices=choices,
|
| 28 |
+
multiselect=multiselect,
|
| 29 |
+
filterable=True,
|
| 30 |
+
allow_custom_value=True,
|
| 31 |
+
value=None,
|
| 32 |
+
info=info,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
def render_intake_panel(chat_input: gr.MultimodalTextbox) -> None:
|
| 37 |
+
countries = country_choices()
|
| 38 |
+
|
| 39 |
with gr.Column(elem_classes=["borderless-form-panel"]):
|
| 40 |
with gr.Row():
|
| 41 |
+
citizenship = _searchable_dropdown(
|
| 42 |
label="Citizenship / passports",
|
| 43 |
+
choices=countries,
|
| 44 |
+
multiselect=True,
|
| 45 |
)
|
| 46 |
+
current_country = _searchable_dropdown(
|
| 47 |
+
label="Current country",
|
| 48 |
+
choices=countries,
|
| 49 |
)
|
| 50 |
with gr.Row():
|
| 51 |
+
residence_status = _searchable_dropdown(
|
| 52 |
+
label="Current residence status",
|
| 53 |
+
choices=RESIDENCE_STATUS_CHOICES,
|
| 54 |
+
)
|
| 55 |
+
education = _searchable_dropdown(
|
| 56 |
label="Education",
|
| 57 |
+
choices=EDUCATION_CHOICES,
|
| 58 |
+
)
|
| 59 |
+
with gr.Row():
|
| 60 |
+
occupation = _searchable_dropdown(
|
| 61 |
+
label="Occupation",
|
| 62 |
+
choices=OCCUPATION_CHOICES,
|
| 63 |
)
|
| 64 |
+
experience = _searchable_dropdown(
|
| 65 |
+
label="Experience",
|
| 66 |
+
choices=EXPERIENCE_CHOICES,
|
| 67 |
)
|
| 68 |
with gr.Row():
|
| 69 |
+
languages = _searchable_dropdown(
|
| 70 |
label="Languages",
|
| 71 |
+
choices=LANGUAGE_CHOICES,
|
| 72 |
+
multiselect=True,
|
| 73 |
)
|
| 74 |
+
budget = _searchable_dropdown(
|
| 75 |
label="Budget",
|
| 76 |
+
choices=BUDGET_CHOICES,
|
| 77 |
)
|
| 78 |
with gr.Row():
|
| 79 |
+
family = _searchable_dropdown(
|
| 80 |
label="Family / dependents",
|
| 81 |
+
choices=FAMILY_CHOICES,
|
| 82 |
)
|
| 83 |
+
timeline = _searchable_dropdown(
|
| 84 |
label="Target timeline",
|
| 85 |
+
choices=TIMELINE_CHOICES,
|
| 86 |
)
|
| 87 |
goals = gr.Textbox(
|
| 88 |
label="Goals in everyday language",
|
|
|
|
| 96 |
fn=build_profile_prompt,
|
| 97 |
inputs=[
|
| 98 |
citizenship,
|
| 99 |
+
current_country,
|
| 100 |
+
residence_status,
|
| 101 |
education,
|
| 102 |
+
occupation,
|
| 103 |
+
experience,
|
| 104 |
languages,
|
| 105 |
budget,
|
| 106 |
family,
|
ui/intake/prompts.py
CHANGED
|
@@ -1,31 +1,60 @@
|
|
| 1 |
# ui/intake/prompts.py
|
| 2 |
from __future__ import annotations
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def _chatbox_value(text: str) -> dict[str, object]:
|
| 6 |
return {"text": text.strip(), "files": []}
|
| 7 |
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def _profile_prompt_text(
|
| 10 |
-
citizenship:
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
goals: str,
|
| 19 |
) -> str:
|
| 20 |
sections = [
|
| 21 |
-
("Citizenship/passports", citizenship),
|
| 22 |
-
("Current location",
|
| 23 |
-
("Education", education),
|
| 24 |
-
("Work history",
|
| 25 |
-
("Languages", languages),
|
| 26 |
-
("Budget and savings", budget),
|
| 27 |
-
("Family/dependents", family),
|
| 28 |
-
("Target timeline", timeline),
|
| 29 |
("Goals and preferences", goals),
|
| 30 |
]
|
| 31 |
details = "\n".join(
|
|
@@ -49,22 +78,26 @@ def _profile_prompt_text(
|
|
| 49 |
|
| 50 |
|
| 51 |
def build_profile_prompt(
|
| 52 |
-
citizenship:
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
| 60 |
goals: str,
|
| 61 |
) -> dict[str, object]:
|
| 62 |
return _chatbox_value(
|
| 63 |
_profile_prompt_text(
|
| 64 |
citizenship,
|
| 65 |
-
|
|
|
|
| 66 |
education,
|
| 67 |
-
|
|
|
|
| 68 |
languages,
|
| 69 |
budget,
|
| 70 |
family,
|
|
|
|
| 1 |
# ui/intake/prompts.py
|
| 2 |
from __future__ import annotations
|
| 3 |
|
| 4 |
+
DropdownValue = str | int | float | list[str | int | float] | None
|
| 5 |
+
|
| 6 |
|
| 7 |
def _chatbox_value(text: str) -> dict[str, object]:
|
| 8 |
return {"text": text.strip(), "files": []}
|
| 9 |
|
| 10 |
|
| 11 |
+
def _format_value(value: DropdownValue) -> str:
|
| 12 |
+
if value is None:
|
| 13 |
+
return ""
|
| 14 |
+
if isinstance(value, list):
|
| 15 |
+
parts = [str(item).strip() for item in value if str(item).strip()]
|
| 16 |
+
return ", ".join(parts)
|
| 17 |
+
return str(value).strip()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _location_text(country: DropdownValue, status: DropdownValue) -> str:
|
| 21 |
+
country_text = _format_value(country)
|
| 22 |
+
status_text = _format_value(status)
|
| 23 |
+
if country_text and status_text:
|
| 24 |
+
return f"{country_text} — {status_text}"
|
| 25 |
+
return country_text or status_text
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _work_history_text(occupation: DropdownValue, experience: DropdownValue) -> str:
|
| 29 |
+
occupation_text = _format_value(occupation)
|
| 30 |
+
experience_text = _format_value(experience)
|
| 31 |
+
if occupation_text and experience_text:
|
| 32 |
+
return f"{occupation_text} — {experience_text}"
|
| 33 |
+
return occupation_text or experience_text
|
| 34 |
+
|
| 35 |
+
|
| 36 |
def _profile_prompt_text(
|
| 37 |
+
citizenship: DropdownValue,
|
| 38 |
+
current_country: DropdownValue,
|
| 39 |
+
residence_status: DropdownValue,
|
| 40 |
+
education: DropdownValue,
|
| 41 |
+
occupation: DropdownValue,
|
| 42 |
+
experience: DropdownValue,
|
| 43 |
+
languages: DropdownValue,
|
| 44 |
+
budget: DropdownValue,
|
| 45 |
+
family: DropdownValue,
|
| 46 |
+
timeline: DropdownValue,
|
| 47 |
goals: str,
|
| 48 |
) -> str:
|
| 49 |
sections = [
|
| 50 |
+
("Citizenship/passports", _format_value(citizenship)),
|
| 51 |
+
("Current location", _location_text(current_country, residence_status)),
|
| 52 |
+
("Education", _format_value(education)),
|
| 53 |
+
("Work history", _work_history_text(occupation, experience)),
|
| 54 |
+
("Languages", _format_value(languages)),
|
| 55 |
+
("Budget and savings", _format_value(budget)),
|
| 56 |
+
("Family/dependents", _format_value(family)),
|
| 57 |
+
("Target timeline", _format_value(timeline)),
|
| 58 |
("Goals and preferences", goals),
|
| 59 |
]
|
| 60 |
details = "\n".join(
|
|
|
|
| 78 |
|
| 79 |
|
| 80 |
def build_profile_prompt(
|
| 81 |
+
citizenship: DropdownValue,
|
| 82 |
+
current_country: DropdownValue,
|
| 83 |
+
residence_status: DropdownValue,
|
| 84 |
+
education: DropdownValue,
|
| 85 |
+
occupation: DropdownValue,
|
| 86 |
+
experience: DropdownValue,
|
| 87 |
+
languages: DropdownValue,
|
| 88 |
+
budget: DropdownValue,
|
| 89 |
+
family: DropdownValue,
|
| 90 |
+
timeline: DropdownValue,
|
| 91 |
goals: str,
|
| 92 |
) -> dict[str, object]:
|
| 93 |
return _chatbox_value(
|
| 94 |
_profile_prompt_text(
|
| 95 |
citizenship,
|
| 96 |
+
current_country,
|
| 97 |
+
residence_status,
|
| 98 |
education,
|
| 99 |
+
occupation,
|
| 100 |
+
experience,
|
| 101 |
languages,
|
| 102 |
budget,
|
| 103 |
family,
|