""" HealixPath Gradio Web Interface A web interface for generating AI-powered persona-driven narratives. """ import gradio as gr import json import os import re from pathlib import Path from dotenv import load_dotenv from huggingface_hub import InferenceClient HEALIX_THEME = gr.themes.Base( primary_hue="lime", secondary_hue="green", neutral_hue="zinc", font=[gr.themes.GoogleFont("Outfit"), "ui-sans-serif", "system-ui", "sans-serif"], font_mono=[gr.themes.GoogleFont("IBM Plex Mono"), "ui-monospace", "monospace"], ).set( body_background_fill="#050805", body_background_fill_dark="#050805", body_text_color="#f3ffe6", body_text_color_dark="#f3ffe6", background_fill_primary="#101e14", background_fill_primary_dark="#101e14", background_fill_secondary="#0a140c", background_fill_secondary_dark="#0a140c", border_color_accent="#b8ff3c", border_color_accent_dark="#b8ff3c", border_color_primary="rgba(184, 255, 60, 0.28)", border_color_primary_dark="rgba(184, 255, 60, 0.28)", button_primary_background_fill="#b8ff3c", button_primary_background_fill_hover="#d4ff6b", button_primary_background_fill_dark="#b8ff3c", button_primary_background_fill_hover_dark="#d4ff6b", button_primary_text_color="#06210f", button_primary_text_color_hover="#06210f", button_primary_text_color_dark="#06210f", button_primary_text_color_hover_dark="#06210f", button_primary_shadow="0 8px 24px rgba(184, 255, 60, 0.4)", link_text_color="#b8ff3c", link_text_color_dark="#b8ff3c", block_radius="16px", button_large_radius="12px", ) # HealixPath identity (lime helix). Logic below this CSS is unchanged. CUSTOM_CSS = """ @import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&family=Syne:wght@700;800&family=IBM+Plex+Mono:wght@400;500&display=swap'); :root { --hp-void: #050805; --hp-panel: #101e14; --hp-lime: #b8ff3c; --hp-lime-2: #d4ff6b; --hp-mint: #9ef6c8; --hp-foam: #f3ffe6; --hp-text: #f3ffe6; --hp-muted: #b4d7bc; --hp-dim: #8aaf93; --hp-line: rgba(184, 255, 60, 0.28); --hp-glow: rgba(184, 255, 60, 0.5); --hp-ink: #06210f; --hp-display: "Syne", "Avenir Next", "Segoe UI", sans-serif; --hp-body: "Outfit", "Segoe UI", system-ui, sans-serif; } @media (prefers-color-scheme: light) { :root { --hp-void: #f4ffea; --hp-panel: #ffffff; --hp-lime: #1f7a00; --hp-lime-2: #278200; --hp-mint: #0c6b3a; --hp-foam: #0b1a10; --hp-text: #0b1a10; --hp-muted: #245c38; --hp-dim: #3c6a4c; --hp-line: rgba(31, 107, 16, 0.3); --hp-glow: rgba(39, 130, 0, 0.22); --hp-ink: #f4ffea; } } html, body, .gradio-container, .gradio-container .main, .app, .contain { font-family: var(--hp-body) !important; background: var(--hp-void) !important; color: var(--hp-text) !important; } body, html { background: radial-gradient(900px 500px at 85% -10%, rgba(184, 255, 60, 0.08), transparent 55%), radial-gradient(600px 400px at 0% 10%, rgba(158, 246, 200, 0.06), transparent 50%), var(--hp-void) !important; } .gradio-container { max-width: 1180px !important; margin: 0 auto !important; padding: 20px 18px 32px !important; background: transparent !important; } .gradio-container a { color: var(--hp-lime) !important; } /* ---- Hero ---- */ .hp-hero { display: grid; grid-template-columns: 120px 1fr; gap: 1.25rem; align-items: center; background: radial-gradient(520px 180px at 12% 50%, var(--hp-glow), transparent 60%), linear-gradient(135deg, color-mix(in srgb, var(--hp-panel) 92%, black), var(--hp-panel)); border: 1px solid var(--hp-line); border-radius: 24px; padding: 20px 24px; box-shadow: 0 0 0 1px rgba(184, 255, 60, 0.08), 0 24px 60px rgba(0, 0, 0, 0.35), 0 0 80px rgba(184, 255, 60, 0.08); overflow: hidden; position: relative; } .hp-helix-wrap { width: 120px; height: 150px; position: relative; } .hp-helix-svg { width: 100%; height: 100%; filter: drop-shadow(0 0 12px var(--hp-glow)); } .hp-helix-svg .strand { stroke-dasharray: 28 8; animation: strand-flow 7s linear infinite; } .hp-helix-svg .strand.b { animation-duration: 9s; animation-direction: reverse; } @keyframes strand-flow { to { stroke-dashoffset: -180; } } .hp-copy h1 { font-family: var(--hp-display) !important; font-weight: 800 !important; letter-spacing: -0.06em; font-size: clamp(2.4rem, 5vw, 4.2rem) !important; line-height: 0.92 !important; margin: 0.15rem 0 0.4rem !important; color: var(--hp-text) !important; } .hp-copy h1 span { color: var(--hp-lime); text-shadow: 0 0 28px var(--hp-glow); } .hp-kicker { margin: 0; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--hp-mint); } .hp-tag { font-family: var(--hp-display); font-weight: 700; font-size: clamp(1.05rem, 2vw, 1.4rem); letter-spacing: -0.03em; color: var(--hp-mint); margin: 0 0 0.45rem; } .hp-lede { margin: 0; color: var(--hp-muted); font-size: 0.98rem; line-height: 1.55; max-width: 46rem; } .card-container { background: var(--hp-panel); border: 1px solid var(--hp-line); border-radius: 16px; padding: 16px 18px; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22); } /* ---- Tabs ---- */ .tabs, .tab-nav { border: 0; background: transparent; } .gradio-container .tabs > div:first-child, .gradio-container .tab-nav, .gradio-container nav[role="tablist"] { display: flex !important; flex-wrap: wrap !important; gap: 6px !important; padding: 6px !important; background: color-mix(in srgb, var(--hp-panel) 90%, black) !important; border: 1px solid var(--hp-line) !important; border-radius: 16px !important; } .gradio-container .tabs button, .gradio-container nav[role="tablist"] button, .gradio-container .tab-nav button { font-family: var(--hp-body) !important; font-weight: 600 !important; color: var(--hp-text) !important; background: transparent !important; border: 1px solid transparent !important; border-radius: 12px !important; padding: 10px 14px !important; transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease !important; } .gradio-container .tabs button:hover, .gradio-container nav[role="tablist"] button:hover { border-color: var(--hp-line) !important; background: color-mix(in srgb, var(--hp-lime) 12%, var(--hp-panel)) !important; transform: translateY(-1px); } .gradio-container .tabs button[aria-selected="true"], .gradio-container nav[role="tablist"] button[aria-selected="true"], .gradio-container .tab-nav button.selected { background: var(--hp-lime) !important; color: var(--hp-ink) !important; border-color: transparent !important; box-shadow: 0 0 24px var(--hp-glow) !important; } /* ---- Inputs ---- */ label, .gradio-container label { color: var(--hp-text) !important; font-weight: 600 !important; font-family: var(--hp-body) !important; } .gradio-container input, .gradio-container textarea, .gradio-container select { background: color-mix(in srgb, var(--hp-void) 80%, var(--hp-panel)) !important; color: var(--hp-text) !important; border: 1px solid var(--hp-line) !important; border-radius: 12px !important; } .gradio-container input:focus, .gradio-container textarea:focus, .gradio-container select:focus { outline: none !important; border-color: var(--hp-lime) !important; box-shadow: 0 0 0 3px var(--hp-glow) !important; } /* ---- Buttons ---- */ .gradio-container button, .gradio-container .gr-button { font-family: var(--hp-body) !important; font-weight: 700 !important; border-radius: 12px !important; transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease !important; } .gradio-container button.primary, .gradio-container .lg.primary, .gradio-container .primary, .gradio-container button[variant="primary"] { background: var(--hp-lime) !important; color: var(--hp-ink) !important; border: 0 !important; box-shadow: 0 8px 24px var(--hp-glow) !important; } .gradio-container button:hover, .gradio-container .gr-button:hover { transform: translateY(-2px); box-shadow: 0 10px 28px var(--hp-glow) !important; } .gradio-container button:active { transform: translateY(0); } .gradio-container button:focus-visible { outline: 2px solid var(--hp-lime) !important; outline-offset: 3px !important; } /* Login should stay obvious even if Gradio marks it secondary */ .gradio-container button:not(.primary) { background: color-mix(in srgb, var(--hp-panel) 80%, black) !important; color: var(--hp-text) !important; border: 1px solid var(--hp-line) !important; } /* Make the first action row (sign-in) pop */ .gradio-container .form, .gradio-container .block, .gradio-container .panel, .gradio-container .gr-group, .gradio-container .gr-box { background: var(--hp-panel) !important; border-color: var(--hp-line) !important; border-radius: 16px !important; } [data-testid="textbox"] textarea { font-family: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace !important; line-height: 1.55 !important; } .gradio-container .markdown-text, .gradio-container .prose, .gradio-container p { color: var(--hp-muted); } .gradio-container h2, .gradio-container h3 { font-family: var(--hp-display) !important; color: var(--hp-text) !important; letter-spacing: -0.03em; } .hp-foot { text-align: center; margin-top: 28px; padding: 18px 8px 4px; border-top: 1px solid var(--hp-line); color: var(--hp-dim); font-size: 0.88rem; } .hp-foot p { margin: 0.2rem 0; } .hp-foot a { color: var(--hp-lime) !important; } footer, .footer, [data-testid="footer"] { background: transparent !important; color: var(--hp-dim) !important; } @media (max-width: 800px) { .hp-hero { grid-template-columns: 1fr; padding: 16px; } .hp-helix-wrap { width: 96px; height: 120px; } } @media (prefers-reduced-motion: reduce) { .hp-helix-svg .strand { animation: none !important; } .gradio-container button, .gradio-container .tabs button { transition: none !important; } .gradio-container button:hover { transform: none !important; } } """ # Load environment variables from .env file load_dotenv() # Load personas def load_personas(): with open("data/personas.json") as f: return json.load(f) personas = load_personas() # Create persona descriptions for dropdown display def create_persona_description(p): """Create a short description of a persona.""" age = p.get("age", "") job_title = p.get("job", {}).get("title", "") location_city = p.get("location", {}).get("city", "") age_label = f"{age}yo" if age else "" return f"{p['name']} | {age_label} {job_title} | {location_city}".strip() # Map display names to persona IDs persona_options = {create_persona_description(p): p["id"] for p in personas} CUSTOM_PERSONA_LABEL = "Other (Custom Persona)" persona_list = list(persona_options.keys()) persona_choices = [CUSTOM_PERSONA_LABEL] + persona_list default_persona_choice = persona_list[0] if persona_list else CUSTOM_PERSONA_LABEL # Free AI backend: Hugging Face Inference Providers. # Every generation runs on the *visitor's* Hugging Face account (Sign in with Hugging Face), # so it uses the visitor's own free monthly allowance. The Space never uses its own token, # a Space secret, or a paid API key for inference. MODEL = os.getenv("HEALIXPATH_MODEL", "openai/gpt-oss-20b") SIGN_IN_MESSAGE = ( "Please sign in with Hugging Face (button at the top of the page) to generate. " "Generations use your own free Hugging Face Inference Providers allowance." ) def get_persona_context(persona_id: str, custom_persona: str = "") -> str: """Format persona data for prompt context.""" if custom_persona: return f"Persona: {custom_persona}" for p in personas: if p["id"] == persona_id: # Handle new persona structure job_title = p.get("job", {}).get("title", "Unknown") industry = p.get("job", {}).get("industry", "Unknown") age = p.get("age", "Unknown") location_city = p.get("location", {}).get("city", "Unknown") goals = p.get("goals", {}).get("primary_goals", []) pain_points = p.get("pain_points", []) motivations = p.get("motivations", []) return f"""Persona: {p["name"]} Age: {age} Location: {location_city} Title: {job_title} Industry: {industry} Background: {p.get("background", "")} Goals: {', '.join(goals) if goals else "N/A"} Pain Points: {', '.join(pain_points) if pain_points else "N/A"} Motivations: {', '.join(motivations) if motivations else "N/A"} User Story: {p.get("user_story", "")}""" return "Persona: Default user" def format_persona_from_json(persona_obj: dict) -> str: """Format a persona object (from generated personas) into context string.""" job_title = persona_obj.get("job", {}).get("title", "Unknown") industry = persona_obj.get("job", {}).get("industry", "Unknown") age = persona_obj.get("age", "Unknown") location_city = persona_obj.get("location", {}).get("city", "Unknown") goals = persona_obj.get("goals", {}).get("primary_goals", []) pain_points = persona_obj.get("pain_points", []) motivations = persona_obj.get("motivations", []) return f"""Persona: {persona_obj.get("name", "Unknown")} Age: {age} Location: {location_city} Title: {job_title} Industry: {industry} Background: {persona_obj.get("background", "")} Goals: {', '.join(goals) if goals else "N/A"} Pain Points: {', '.join(pain_points) if pain_points else "N/A"} Motivations: {', '.join(motivations) if motivations else "N/A"} User Story: {persona_obj.get("user_story", "")}""" def build_persona_profile(persona_name: str, persona_override: str): """Return the persona label for display and the context payload. Returns (label, contexts_list) where contexts_list is a list of persona contexts.""" # Check if persona_override contains JSON (generated persona) if persona_override and persona_override.strip(): stripped = persona_override.strip() if stripped.startswith('{') or stripped.startswith('['): try: persona_json = json.loads(stripped) # If it's an array, return all personas if isinstance(persona_json, list) and len(persona_json) > 0: contexts = [format_persona_from_json(p) for p in persona_json if isinstance(p, dict)] return f"{len(contexts)} Generated Personas", contexts # If it's a single persona object, use it directly elif isinstance(persona_json, dict) and 'id' in persona_json: return persona_json.get('name', 'Generated Persona'), [format_persona_from_json(persona_json)] except json.JSONDecodeError: pass # Fall through to custom persona handling if persona_name == CUSTOM_PERSONA_LABEL: custom_label = persona_override.strip() or "Custom Persona" context = get_persona_context("", custom_label) return custom_label, [context] persona_id = persona_options.get(persona_name, "busy_parent") context = get_persona_context(persona_id) return persona_name or "Persona", [context] def toggle_custom_persona(selected_value: str): """Show the custom persona textbox only when 'Other' is selected.""" show_custom = selected_value == CUSTOM_PERSONA_LABEL return gr.update(visible=show_custom, value="" if not show_custom else None) def resolve_token(oauth_token=None, request=None): """Return the visitor's own Hugging Face token, or None. Order: the OAuth token from "Sign in with Hugging Face", then a Bearer token the caller sent in the Authorization header (for MCP clients that pass their own token). Never falls back to a Space-level token or secret. """ token = getattr(oauth_token, "token", None) if token: return token try: auth = request.headers.get("authorization", "") if request is not None else "" except Exception: auth = "" if auth.lower().startswith("bearer ") and auth[7:].strip(): return auth[7:].strip() return None def _strip_code_fence(text: str) -> str: text = (text or "").strip() if text.startswith("```"): text = re.sub(r"^```[a-zA-Z]*\s*", "", text) text = re.sub(r"\s*```$", "", text).strip() return text def generate_text(system_prompt: str, user_prompt: str, token, max_tokens: int = 1500) -> str: """Call an open model through HF Inference Providers with the visitor's token.""" if not token: return json.dumps({"error": "Sign in required", "message": SIGN_IN_MESSAGE}, indent=2) try: client = InferenceClient(api_key=token) result = client.chat_completion( model=MODEL, messages=[ {"role": "system", "content": system_prompt}, {"role": "user", "content": user_prompt}, ], max_tokens=max_tokens, temperature=0.7, ) return _strip_code_fence(result.choices[0].message.content or "") except Exception as e: return json.dumps({ "error": type(e).__name__, "message": f"Hugging Face Inference Providers call failed: {e}", }, indent=2) def generate_user_story(product: str, persona_name: str, persona_override: str, oauth_token: gr.OAuthToken | None = None, request: gr.Request = None): """Generate a user story for the given product and persona(s).""" token = resolve_token(oauth_token, request) _, persona_contexts = build_persona_profile(persona_name, persona_override) system_prompt = """You are an expert UX writer and product strategist. Generate a structured user story in JSON format with the following fields: - story: A concise user story - acceptance_criteria: Array of 3-5 acceptance criteria - risks: Array of 2-3 potential risks or challenges Return ONLY valid JSON, no additional text.""" results = [] for idx, persona_context in enumerate(persona_contexts): user_prompt = f"""{persona_context} Generate a user story for this persona using the product: {product} Format as JSON with the keys: story, acceptance_criteria (array), risks (array)""" response = generate_text(system_prompt, user_prompt, token) try: data = json.loads(response) if len(persona_contexts) > 1: data['persona_index'] = idx + 1 results.append(data) except: results.append({"error": "Failed to parse response", "raw": response}) return json.dumps(results if len(results) > 1 else results[0], indent=2) def generate_experience_tale(problem: str, persona_name: str, persona_override: str, oauth_token: gr.OAuthToken | None = None, request: gr.Request = None): """Generate a customer experience tale.""" token = resolve_token(oauth_token, request) _, persona_contexts = build_persona_profile(persona_name, persona_override) system_prompt = """You are an expert in customer experience and user research. Generate a narrative about a persona experiencing a problem in JSON format with: - title: A compelling title - narrative: A detailed story (2-3 paragraphs) - pain_points: Array of 3-4 pain points - opportunities: Array of 2-3 improvement opportunities Return ONLY valid JSON, no additional text.""" results = [] for idx, persona_context in enumerate(persona_contexts): user_prompt = f"""{persona_context} Describe how this persona experiences this problem: {problem} Format as JSON with keys: title, narrative, pain_points (array), opportunities (array)""" response = generate_text(system_prompt, user_prompt, token) try: data = json.loads(response) if len(persona_contexts) > 1: data['persona_index'] = idx + 1 results.append(data) except: results.append({"error": "Failed to parse response", "raw": response}) return json.dumps(results if len(results) > 1 else results[0], indent=2) def generate_feature_impact(feature: str, persona_name: str, persona_override: str, oauth_token: gr.OAuthToken | None = None, request: gr.Request = None): """Generate a before/after feature impact story.""" token = resolve_token(oauth_token, request) _, persona_contexts = build_persona_profile(persona_name, persona_override) system_prompt = """You are an expert at showing product impact through user narratives. Generate a before/after story in JSON format with: - before_story: How the persona struggled before - after_story: How the feature improved their experience - key_benefits: Array of 3-4 key benefits - success_metrics: Array of 2-3 measurable success metrics Return ONLY valid JSON, no additional text.""" results = [] for idx, persona_context in enumerate(persona_contexts): user_prompt = f"""{persona_context} Show the before/after impact of this feature on the persona's experience: {feature} Format as JSON with keys: before_story, after_story, key_benefits (array), success_metrics (array)""" response = generate_text(system_prompt, user_prompt, token) try: data = json.loads(response) if len(persona_contexts) > 1: data['persona_index'] = idx + 1 results.append(data) except: results.append({"error": "Failed to parse response", "raw": response}) return json.dumps(results if len(results) > 1 else results[0], indent=2) def generate_journey_story(stage: str, product: str, persona_name: str, persona_override: str, oauth_token: gr.OAuthToken | None = None, request: gr.Request = None): """Generate a journey map narrative.""" token = resolve_token(oauth_token, request) _, persona_contexts = build_persona_profile(persona_name, persona_override) system_prompt = """You are an expert in customer journey mapping and experience design. Generate a journey stage narrative in JSON format with: - stage: The journey stage name - narrative: Detailed description of what the persona experiences - touchpoints: Array of 3-4 key touchpoints - emotions: Array of 2-3 emotions the persona experiences - breakdowns: Array of 1-2 potential friction points - opportunities: Array of 2-3 improvement opportunities Return ONLY valid JSON, no additional text.""" results = [] for idx, persona_context in enumerate(persona_contexts): user_prompt = f"""{persona_context} Describe this persona's experience at the '{stage}' stage of their journey with {product}. Format as JSON with keys: stage, narrative, touchpoints (array), emotions (array), breakdowns (array), opportunities (array)""" response = generate_text(system_prompt, user_prompt, token) try: data = json.loads(response) if len(persona_contexts) > 1: data['persona_index'] = idx + 1 results.append(data) except: results.append({"error": "Failed to parse response", "raw": response}) return json.dumps(results if len(results) > 1 else results[0], indent=2) # Persona browser functions def search_personas_func(role: str, industry: str, age_range: str, tech_literacy: str, location: str): """Search personas based on filters.""" filtered = personas # Apply filters if role and role.strip(): filtered = [p for p in filtered if role.lower() in p.get("job", {}).get("title", "").lower()] if industry and industry.strip(): filtered = [p for p in filtered if industry.lower() in p.get("job", {}).get("industry", "").lower()] if age_range and age_range.strip(): try: min_age, max_age = map(int, age_range.split("-")) filtered = [p for p in filtered if min_age <= p.get("age", 0) <= max_age] except: pass if tech_literacy and tech_literacy.strip(): filtered = [p for p in filtered if tech_literacy.lower() in p.get("technology", {}).get("tech_literacy", "").lower()] if location and location.strip(): filtered = [p for p in filtered if location.lower() in p.get("location", {}).get("city", "").lower() or location.lower() in p.get("location", {}).get("state", "").lower() or location.lower() in p.get("location", {}).get("country", "").lower()] # Format results as a table if not filtered: return "No personas found matching the criteria.", "" result_lines = [f"**Found {len(filtered)} persona(s):**\n"] for p in filtered[:20]: # Limit to 20 results name = p.get("name", "Unknown") age = p.get("age", "?") title = p.get("job", {}).get("title", "Unknown") industry_val = p.get("job", {}).get("industry", "Unknown") city = p.get("location", {}).get("city", "Unknown") tech_lit = p.get("technology", {}).get("tech_literacy", "Unknown") result_lines.append(f"• **{name}** ({age}) - {title} @ {industry_val} | {city} | Tech: {tech_lit}") return "\n".join(result_lines), json.dumps(filtered[0] if filtered else {}, indent=2) def list_all_personas(): """List all personas with summary info.""" result_lines = [f"**Total Personas: {len(personas)}**\n"] # Group by industry by_industry = {} for p in personas: industry = p.get("job", {}).get("industry", "Other") if industry not in by_industry: by_industry[industry] = [] by_industry[industry].append(p) result_lines.append("**By Industry:**") for industry, persona_list in sorted(by_industry.items()): result_lines.append(f"• {industry}: {len(persona_list)} personas") result_lines.append("\n**All Personas:**") for p in personas[:20]: # Show first 20 name = p.get("name", "Unknown") age = p.get("age", "?") title = p.get("job", {}).get("title", "Unknown") city = p.get("location", {}).get("city", "Unknown") result_lines.append(f"• **{name}** ({age}) - {title} | {city}") if len(personas) > 20: result_lines.append(f"\n_... and {len(personas) - 20} more personas_") return "\n".join(result_lines) def show_persona_details(persona_index: int): """Show detailed information about a specific persona.""" if 0 <= persona_index < len(personas): p = personas[persona_index] return json.dumps(p, indent=2) return "Persona not found" def generate_personas_func(description: str, count: int, oauth_token: gr.OAuthToken | None = None, request: gr.Request = None): """Generate random personas based on description using an open model via Hugging Face.""" token = resolve_token(oauth_token, request) if not description or not description.strip(): return json.dumps({"error": "Please provide a description"}, indent=2) if count < 1 or count > 5: return json.dumps({"error": "Count must be between 1 and 5"}, indent=2) if not token: return json.dumps({"error": "Sign in required", "message": SIGN_IN_MESSAGE}, indent=2) system_prompt = """You are a persona generation expert. Generate realistic, diverse user personas based on the provided description. CRITICAL REQUIREMENTS: 1. Return ONLY valid JSON - no markdown, no code blocks, no explanations 2. Return a JSON array of persona objects 3. Each persona must follow the exact structure provided in the example 4. Ensure diversity in all randomized fields (location, income, education, tech literacy, devices, etc.) 5. All personas must match the core description provided by the user 6. Generate exactly the number of personas requested PERSONA STRUCTURE (follow this exactly): { "id": "UUID (e.g., 'a1b2c3d4-e5f6-7890-abcd-ef1234567890')", "name": "Full Name", "age": number, "gender": "Male/Female/Nonbinary", "location": { "address": "street address", "city": "city", "state": "state/province", "country": "country" }, "demographics": { "income": "$XX,000/year", "education_level": "education level", "marital_status": "status", "household_size": number }, "job": { "title": "job title", "industry": "industry", "experience_years": number, "employment_type": "Full-time/Part-time/Freelance/etc" }, "background": "brief background description", "interests": ["interest1", "interest2", "interest3"], "purchasing_habits": { "online_shopping_frequency": "frequency", "preferred_platforms": ["platform1", "platform2"], "average_spend_per_month": "$XXX", "brand_loyalty_level": "Low/Medium/High/Very High" }, "technology": { "tech_literacy": "Low/Medium/High/Very High", "devices_used": ["device1", "device2"], "favorite_apps": ["app1", "app2", "app3"] }, "goals": { "primary_goals": ["goal1", "goal2"], "secondary_goals": ["goal1", "goal2"] }, "pain_points": ["pain1", "pain2"], "motivations": ["motivation1", "motivation2"], "personality": { "traits": ["trait1", "trait2"], "communication_style": "style description" }, "user_story": "As a [role], I want [goal] so [benefit].", "acceptance_criteria": ["criteria1", "criteria2"] }""" user_prompt = f"""Generate {count} diverse user persona{'s' if count > 1 else ''} that match this description: "{description}" Requirements: - Generate exactly {count} persona{'s' if count > 1 else ''} - Each persona MUST match the core description: "{description}" - Randomize other attributes for diversity (locations worldwide, various incomes, different tech literacy levels, diverse jobs/industries, etc.) - Ensure realistic consistency within each persona - Use diverse names from various cultures - Return ONLY the JSON array, no other text Return format: [persona1, persona2, ...]""" try: response_text = generate_text(system_prompt, user_prompt, token, max_tokens=4096) if response_text.lstrip().startswith("{") and '"error"' in response_text[:40]: return response_text # Clean up response (remove markdown code blocks if present) cleaned_response = response_text.strip() if cleaned_response.startswith("```json"): cleaned_response = cleaned_response.replace("```json", "").replace("```", "").strip() elif cleaned_response.startswith("```"): cleaned_response = cleaned_response.replace("```", "").strip() # Validate JSON personas_data = json.loads(cleaned_response) if not isinstance(personas_data, list): return json.dumps({"error": "Response is not an array"}, indent=2) return json.dumps(personas_data, indent=2) except Exception as e: return json.dumps({"error": f"Failed to generate personas: {str(e)}"}, indent=2) # Build the Gradio interface with gr.Blocks(title="HealixPath — stories that spiral from a persona", theme=HEALIX_THEME, css=CUSTOM_CSS) as demo: gr.HTML( """
Team Healix · persona storytelling
Stories that spiral from a persona.
Sign in with Hugging Face to generate stories, journeys, and personas on free open models, using your own allowance. Co-authored with DevRubenArevalo.
Choose a persona or add your own, then craft structured narratives to inform product decisions and user experiences. Sign in to generate; browsing personas works while signed out.
Generate customer experience narratives highlighting pain points and opportunities.
Show before/after impact stories demonstrating feature value.
Generate journey stage narratives with touchpoints and emotions.
HealixPath — Mackenzie O’Brien, Mac Labs AI, and DevRubenArevalo.
Project page · Frozen hackathon Space · Collection · Open models via Hugging Face Inference Providers