Added uiux Module
Browse files- app/main.py +4 -1
- app/rag/embeddings.py +2 -2
- app/rag/prompt_library.py +19 -1
- app/rag/utils.py +4 -1
- app/uiux/__init__.py +0 -0
- app/uiux/models.py +24 -0
- app/uiux/prompts.py +70 -0
- app/uiux/routes.py +22 -0
- app/uiux/service.py +54 -0
app/main.py
CHANGED
|
@@ -17,7 +17,7 @@ from app.seo import routes as seo_routes
|
|
| 17 |
from app.page_speed import routes as page_speed_routes
|
| 18 |
from app.content_relevence import routes as content_relevance_routes
|
| 19 |
from app.keywords.routes import router as keywords_router
|
| 20 |
-
|
| 21 |
|
| 22 |
# app/suppress_warnings.py
|
| 23 |
|
|
@@ -90,6 +90,9 @@ app.include_router(page_speed_routes.router)
|
|
| 90 |
# Mount the keywords router
|
| 91 |
app.include_router(keywords_router)
|
| 92 |
|
|
|
|
|
|
|
|
|
|
| 93 |
# Add CORS middleware
|
| 94 |
app.add_middleware(
|
| 95 |
CORSMiddleware,
|
|
|
|
| 17 |
from app.page_speed import routes as page_speed_routes
|
| 18 |
from app.content_relevence import routes as content_relevance_routes
|
| 19 |
from app.keywords.routes import router as keywords_router
|
| 20 |
+
from app.uiux import routes as uiux_routes
|
| 21 |
|
| 22 |
# app/suppress_warnings.py
|
| 23 |
|
|
|
|
| 90 |
# Mount the keywords router
|
| 91 |
app.include_router(keywords_router)
|
| 92 |
|
| 93 |
+
# Mount UI/UX router
|
| 94 |
+
app.include_router(uiux_routes.router)
|
| 95 |
+
|
| 96 |
# Add CORS middleware
|
| 97 |
app.add_middleware(
|
| 98 |
CORSMiddleware,
|
app/rag/embeddings.py
CHANGED
|
@@ -8,13 +8,13 @@ load_dotenv()
|
|
| 8 |
|
| 9 |
def get_llm():
|
| 10 |
"""
|
| 11 |
-
Returns a ChatGroq LLM instance
|
| 12 |
stored in the environment.
|
| 13 |
"""
|
| 14 |
from langchain_groq import ChatGroq
|
| 15 |
|
| 16 |
llm = ChatGroq(
|
| 17 |
-
model="
|
| 18 |
temperature=0,
|
| 19 |
max_tokens=1024,
|
| 20 |
api_key=os.getenv("GROQ_API_KEY", "")
|
|
|
|
| 8 |
|
| 9 |
def get_llm():
|
| 10 |
"""
|
| 11 |
+
Returns a ChatGroq LLM instance using the GROQ API key
|
| 12 |
stored in the environment.
|
| 13 |
"""
|
| 14 |
from langchain_groq import ChatGroq
|
| 15 |
|
| 16 |
llm = ChatGroq(
|
| 17 |
+
model="openai/gpt-oss-120b",
|
| 18 |
temperature=0,
|
| 19 |
max_tokens=1024,
|
| 20 |
api_key=os.getenv("GROQ_API_KEY", "")
|
app/rag/prompt_library.py
CHANGED
|
@@ -97,4 +97,22 @@ content_relevance_prompt = ChatPromptTemplate.from_messages([
|
|
| 97 |
|
| 98 |
# ──────────────────────────────────────────────────────────────────────────────
|
| 99 |
# 5. Prompt Template for UI/UX RAG Chatbot
|
| 100 |
-
# ──────────────────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
# ──────────────────────────────────────────────────────────────────────────────
|
| 99 |
# 5. Prompt Template for UI/UX RAG Chatbot
|
| 100 |
+
# ──────────────────────────────────────────────────────────────────────────────
|
| 101 |
+
|
| 102 |
+
uiux_prompt_template = """
|
| 103 |
+
You are a UI/UX Assistant specialized in analyzing user interface and experience data.
|
| 104 |
+
Use the provided context (UI/UX metrics and user feedback) to answer the user's question.
|
| 105 |
+
If the context lacks sufficient information, respond with "I don't know." Avoid fabricating details.
|
| 106 |
+
|
| 107 |
+
Retrieved context:
|
| 108 |
+
{context}
|
| 109 |
+
|
| 110 |
+
User's question:
|
| 111 |
+
{question}
|
| 112 |
+
|
| 113 |
+
Your response:
|
| 114 |
+
"""
|
| 115 |
+
uiux_prompt = ChatPromptTemplate.from_messages([
|
| 116 |
+
("system", uiux_prompt_template),
|
| 117 |
+
("human", "{question}"),
|
| 118 |
+
])
|
app/rag/utils.py
CHANGED
|
@@ -15,7 +15,8 @@ from .prompt_library import (
|
|
| 15 |
default_user_prompt,
|
| 16 |
page_speed_prompt,
|
| 17 |
seo_prompt,
|
| 18 |
-
content_relevance_prompt
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
# 1. Path with doc_type
|
|
@@ -94,6 +95,8 @@ def build_rag_chain(
|
|
| 94 |
user_prompt = seo_prompt
|
| 95 |
elif prompt_type == "content_relevance":
|
| 96 |
user_prompt = content_relevance_prompt
|
|
|
|
|
|
|
| 97 |
else:
|
| 98 |
user_prompt = default_user_prompt
|
| 99 |
|
|
|
|
| 15 |
default_user_prompt,
|
| 16 |
page_speed_prompt,
|
| 17 |
seo_prompt,
|
| 18 |
+
content_relevance_prompt,
|
| 19 |
+
uiux_prompt
|
| 20 |
)
|
| 21 |
|
| 22 |
# 1. Path with doc_type
|
|
|
|
| 95 |
user_prompt = seo_prompt
|
| 96 |
elif prompt_type == "content_relevance":
|
| 97 |
user_prompt = content_relevance_prompt
|
| 98 |
+
elif prompt_type == "uiux":
|
| 99 |
+
user_prompt = uiux_prompt
|
| 100 |
else:
|
| 101 |
user_prompt = default_user_prompt
|
| 102 |
|
app/uiux/__init__.py
ADDED
|
File without changes
|
app/uiux/models.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ----------------------------
|
| 2 |
+
# app/uiux/models.py
|
| 3 |
+
# ----------------------------
|
| 4 |
+
from pydantic import BaseModel, Field
|
| 5 |
+
from typing import Any, Dict, List
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class UIUXRequest(BaseModel):
|
| 9 |
+
"""Payload for incoming UI/UX metrics."""
|
| 10 |
+
uiux_data: Dict[str, Any]
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class PrioritySuggestions(BaseModel):
|
| 14 |
+
"""Categorized UI/UX suggestions by effort level."""
|
| 15 |
+
high: List[str] = Field(..., description="High-effort suggestion strings.")
|
| 16 |
+
medium: List[str] = Field(..., description="Medium-effort suggestion strings.")
|
| 17 |
+
low: List[str] = Field(..., description="Low-effort suggestion strings.")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class Recommendation(BaseModel):
|
| 21 |
+
"""Wrapper for prioritized UI/UX suggestions."""
|
| 22 |
+
priority_suggestions: PrioritySuggestions = Field(
|
| 23 |
+
..., description="All UI/UX suggestions categorized by effort level."
|
| 24 |
+
)
|
app/uiux/prompts.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ----------------------------
|
| 2 |
+
# app/uiux/prompts.py
|
| 3 |
+
# ----------------------------
|
| 4 |
+
|
| 5 |
+
class UIUXPrompts:
|
| 6 |
+
"""
|
| 7 |
+
Prompt templates for UI/UX analysis services.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
SYSTEM_PROMPT = """
|
| 11 |
+
You are an **Expert UI/UX Analyst & Designer** with extensive expertise in usability heuristics, visual hierarchy, responsive design, and WCAG accessibility guidelines.
|
| 12 |
+
|
| 13 |
+
Your job is to review the provided UI/UX metrics and produce **only** a valid JSON object with one key: `priority_suggestions`.
|
| 14 |
+
|
| 15 |
+
Requirements:
|
| 16 |
+
1. `priority_suggestions` must map to an object with exactly three arrays: `high`, `medium`, `low`.
|
| 17 |
+
2. Each array item must be a single, clear English sentence.
|
| 18 |
+
3. Prefix each suggestion with a category tag in square brackets (e.g., `[Accessibility]`, `[Hierarchy]`, `[Navigation]`).
|
| 19 |
+
4. End each suggestion with the effort level in parentheses, e.g., `(Effort Level: high)`, `(Effort Level: medium)`, `(Effort Level: low)`.
|
| 20 |
+
5. Within each array, order suggestions by expected impact (highest first).
|
| 21 |
+
6. Ensure the output is strictly JSON—no additional text, comments, or keys.
|
| 22 |
+
7. Validate JSON syntax: keys and strings must be enclosed in double quotes.
|
| 23 |
+
|
| 24 |
+
{format_instructions}
|
| 25 |
+
|
| 26 |
+
Input Report Data:
|
| 27 |
+
{report}
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
REPORT_PROMPT = """
|
| 31 |
+
You are an **Expert UI/UX Consultant** focused on delivering concise, actionable audit reports.
|
| 32 |
+
|
| 33 |
+
Using the given UI/UX metrics JSON, generate a text report with these exact sections and formatting:
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
**1. Overall Summary** (max 50 words)
|
| 37 |
+
- **UX Score**: (0–100)
|
| 38 |
+
- **Grade**: A–F (include legend: A=90–100, B=80–89, C=70–79, D=60–69, F<60)
|
| 39 |
+
- **Top 3 Strengths**: Three bullet points
|
| 40 |
+
- **Top 3 Issues**: Three bullet points
|
| 41 |
+
|
| 42 |
+
---
|
| 43 |
+
**2. Metric Breakdown**
|
| 44 |
+
For each metric in the input data, include:
|
| 45 |
+
- **Metric**: Name
|
| 46 |
+
- **Summary**: One-line highlight (avoid raw JSON)
|
| 47 |
+
- **Status**: Good / Needs Improvement / Poor
|
| 48 |
+
- **Rationale**: One-sentence user-impact statement
|
| 49 |
+
- **Recommendation**: One-sentence clear action
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
**3. Action Plan** (5 items)
|
| 53 |
+
List the five highest-priority fixes in order:
|
| 54 |
+
1. **Metric**: Name
|
| 55 |
+
- **Action**: Short description
|
| 56 |
+
- **Effort**: low / medium / high
|
| 57 |
+
|
| 58 |
+
---
|
| 59 |
+
**4. Monitoring Strategy** (max 5 lines)
|
| 60 |
+
- **Cadence**: weekly or monthly
|
| 61 |
+
- **Metrics**: list 2–3 key metrics to track
|
| 62 |
+
|
| 63 |
+
---
|
| 64 |
+
**Guidelines**:
|
| 65 |
+
- Do not include raw JSON or extra sections.
|
| 66 |
+
- Use consistent Markdown styling as shown.
|
| 67 |
+
|
| 68 |
+
UI/UX Data JSON:
|
| 69 |
+
{uiux_data}
|
| 70 |
+
"""
|
app/uiux/routes.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, HTTPException
|
| 2 |
+
from app.uiux.models import UIUXRequest
|
| 3 |
+
from app.uiux.service import UIUXService
|
| 4 |
+
|
| 5 |
+
router = APIRouter(prefix="/uiux", tags=["UIUX"])
|
| 6 |
+
uiux_service = UIUXService()
|
| 7 |
+
|
| 8 |
+
@router.post("/generate-full-report")
|
| 9 |
+
def generate_full_uiux_analysis(request: UIUXRequest):
|
| 10 |
+
"""
|
| 11 |
+
Generate full UI/UX analysis: report + prioritized suggestions.
|
| 12 |
+
"""
|
| 13 |
+
try:
|
| 14 |
+
report = uiux_service.generate_uiux_report(request.uiux_data)
|
| 15 |
+
priority_suggestions = uiux_service.generate_uiux_priority(report)
|
| 16 |
+
return {
|
| 17 |
+
"success": True,
|
| 18 |
+
"report": report,
|
| 19 |
+
"priority_suggestions": priority_suggestions
|
| 20 |
+
}
|
| 21 |
+
except Exception as e:
|
| 22 |
+
raise HTTPException(status_code=500, detail=str(e))
|
app/uiux/service.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Any
|
| 2 |
+
import os
|
| 3 |
+
import getpass
|
| 4 |
+
import logging
|
| 5 |
+
from app.uiux.models import Recommendation, PrioritySuggestions
|
| 6 |
+
from app.uiux.prompts import UIUXPrompts
|
| 7 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 8 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 9 |
+
from langchain_core.output_parsers import PydanticOutputParser
|
| 10 |
+
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
+
class UIUXService:
|
| 14 |
+
"""
|
| 15 |
+
Service class for generating UI/UX reports and prioritized suggestions via LLM.
|
| 16 |
+
"""
|
| 17 |
+
def __init__(self):
|
| 18 |
+
key = os.getenv("GEMINI_API_KEY")
|
| 19 |
+
if not key:
|
| 20 |
+
key = getpass.getpass("Enter your Gemini API key: ")
|
| 21 |
+
self.llm = ChatGoogleGenerativeAI(
|
| 22 |
+
model="gemini-2.5-flash",
|
| 23 |
+
temperature=0,
|
| 24 |
+
api_key=key
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Report prompt template
|
| 28 |
+
self.report_prompt = ChatPromptTemplate.from_messages([
|
| 29 |
+
("system", UIUXPrompts.REPORT_PROMPT),
|
| 30 |
+
("human", "Please generate a comprehensive UI/UX audit report based on the following data:\n\n{uiux_data}")
|
| 31 |
+
])
|
| 32 |
+
|
| 33 |
+
# Priority suggestions parser
|
| 34 |
+
self.parser = PydanticOutputParser(pydantic_object=Recommendation)
|
| 35 |
+
self.priority_chain = (
|
| 36 |
+
ChatPromptTemplate.from_messages([
|
| 37 |
+
("system", UIUXPrompts.SYSTEM_PROMPT),
|
| 38 |
+
("human", "{report}")
|
| 39 |
+
]).partial(format_instructions=self.parser.get_format_instructions())
|
| 40 |
+
| self.llm
|
| 41 |
+
| self.parser
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
def generate_uiux_report(self, uiux_data: Dict[str, Any]) -> str:
|
| 45 |
+
logger.info("Generating UI/UX report via LLM...")
|
| 46 |
+
prompt_input = {"uiux_data": uiux_data}
|
| 47 |
+
response = self.report_prompt | self.llm
|
| 48 |
+
result = response.invoke(prompt_input)
|
| 49 |
+
return result.content.strip()
|
| 50 |
+
|
| 51 |
+
def generate_uiux_priority(self, report: str) -> PrioritySuggestions:
|
| 52 |
+
logger.info("Generating prioritized UX suggestions via chain...")
|
| 53 |
+
rec: Recommendation = self.priority_chain.invoke({"report": report})
|
| 54 |
+
return rec.priority_suggestions
|