CoolFace
Apppublic

TanishaGupta30/layout-optima

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

๐ŸŽจ Layout-Optima

AI-Driven UI/UX Layout Optimisation โ€” Scaler ร— Meta ร— HuggingFace Hackathon submission.

Simulates CRO (Conversion Rate Optimisation) by letting an agent rearrange webpage components to maximise engagement and conversion scores across 3 tasks of increasing difficulty.


Tasks

TaskDifficultyGoalScore Metric
cta_visibilityEasyMove CTA button above the fold (index < 2)Linear proximity
content_prioritizeMediumSort sections by descending dwell timePearson correlation
form_frictionHardPlace trust signals before friction componentsShielded fraction

Observation Space

json
{
  "task_id": "cta_visibility",
  "task_description": "Move the CTA button above the fold (index < 2)...",
  "step": 0,
  "max_steps": 20,
  "score": 0.2,
  "components": [
    {
      "id": "CTA_BUTTON",
      "type": "cta",
      "label": "Sign Up Free",
      "index": 5,
      "dwell_time": 1.1,
      "click_count": 22,
      "conversion_rate": 0.41,
      "scroll_depth": 0.15
    }
  ],
  "heatmap_summary": {
    "top_dwell_time": [...],
    "friction_points": [...],
    "trust_signals": [...],
    "cta_components": [...]
  },
  "available_actions": ["move_component", "change_color", "remove_component"]
}

Action Space

json
{"type": "move_component",  "id": "<component_id>", "new_index": 1}
{"type": "change_color",    "id": "<component_id>", "hex": "#FF5733"}
{"type": "remove_component","id": "<component_id>"}

Reward

EventReward
Score improvement (delta)delta + 0.05
No improvementdelta (โ‰ค 0)
Task solved (score โ‰ฅ 1.0)+0.5 bonus
Invalid action-0.02
No-op-0.01

HTTP API (OpenEnv spec)

MethodPathDescription
GET/healthHealth check โ€” returns 200
GET/tasksList all task ids
POST/resetStart new episode {"task_id":"cta_visibility"}
POST/stepExecute action {"task_id":"...", "action":{...}}
GET/state?task_id=...Episode metadata

Environment Variables

VariableDescription
API_BASE_URLLLM API endpoint (OpenAI-compatible)
MODEL_NAMEModel identifier for inference
HF_TOKENHugging Face / API key

Run Locally

bash $env:ENVBASEURL = "https://tanishagupta30-layout-optima.hf.space"

> python inference.py

File Structure

โ”œโ”€โ”€ app.py            # FastAPI + Gradio server (OpenEnv endpoints + web UI)
โ”œโ”€โ”€ env.py            # LayoutOptimaEnv โ€” reset/step/state/grade logic
โ”œโ”€โ”€ inference.py      # Inference runner with [START]/[STEP]/[END] logs
โ”œโ”€โ”€ tasks.py          # Component dataclass + 3 task definitions
โ”œโ”€โ”€ openenv.yaml      # OpenEnv spec manifest
โ”œโ”€โ”€ requirements.txt  # Python dependencies
โ”œโ”€โ”€ Dockerfile        # Container definition
โ””โ”€โ”€ README.md         # This file