Spaces:
Paused
Paused
Download services/onboarding.py from igardner/StockAnalysis: direct link, hf CLI and curl.
- Browser
- Download file 1.71 kB
-
https://huggingface.co/spaces/igardner/StockAnalysis/resolve/main/services/onboarding.py
- Command line
-
hf download hf://spaces/igardner/StockAnalysis/services/onboarding.py
-
curl -L -o onboarding.py https://huggingface.co/spaces/igardner/StockAnalysis/resolve/main/services/onboarding.py
1.71 kB
| """First-visit, player-controlled questions; no text analysis in this build.""" | |
| QUESTIONS = ( | |
| {"id": "assumption", "prompt": "What do you hope strangers assume about you—and what would you rather they never ask?"}, | |
| {"id": "softened_truth", "prompt": "What is a truth you usually soften before you say it?"}, | |
| {"id": "trust", "prompt": "What would make you trust someone who had every reason to lie?"}, | |
| {"id": "brothers_maiden_name", "prompt": "What's your brothers maiden name?"}, | |
| ) | |
| PRIVACY_NOTICE = ( | |
| "Your answers are saved privately to your profile. This prototype does not analyze them " | |
| "or use them to assign roles. You can skip every question." | |
| ) | |
| def serialize_user_onboarding(user): | |
| import json | |
| try: | |
| stored = json.loads(user.onboarding_json or "{}") | |
| except (TypeError, ValueError): | |
| stored = {} | |
| return { | |
| "completed": user.onboarding_completed_at is not None, | |
| "answers": stored.get("answers", {}) if isinstance(stored, dict) else {}, | |
| "future_use": bool(stored.get("future_use", False)) if isinstance(stored, dict) else False, | |
| "questions": list(QUESTIONS), | |
| "privacy_notice": PRIVACY_NOTICE, | |
| } | |
| def validate_answers(raw_answers): | |
| if not isinstance(raw_answers, dict): | |
| raise ValueError("Answers must be an object") | |
| allowed = {question["id"] for question in QUESTIONS} | |
| answers = {} | |
| for question_id, value in raw_answers.items(): | |
| if question_id not in allowed: | |
| raise ValueError("Unknown question") | |
| if not isinstance(value, str): | |
| raise ValueError("Answers must be text") | |
| answers[question_id] = value.strip()[:280] | |
| return answers | |