use brevity and shorten req list ### Detailed Requirements List for Relationship Mediator LLM App
#### **1. Core Functional Requirements**

**1.1 Mediation Interface**  
- **User Input Channels**:  
  - Two input fields for User A and User B (text-based).  
  - Voice-to-text via button-press and microphone per users (STT).  
  - Send buttons to submit messages (text/voice).  

**1.2 Message Display**  
- **Bubble Styling**:  
  - Messages from User A: Right-aligned, blue background, white text.  
  - Messages from User B: Left-aligned, green background, white text.  
  - Mediator responses: Center-aligned, light gray background, black text.  
  - Timestamps displayed for each message.  
- **HTML Rendering**: Use `<div>` elements with inline CSS for bubble effects (padding, rounded corners, alignment).  

**1.3 Context Management & Summarization**  
- **Automatic Summarization**:  
  - After every **10 message pairs** (User + Mediator), trigger a summary.  
  - Summary is generated using the LLM (Ollama) with a predefined prompt.  
  - Retain the **4 most recent messages** post-summarization to maintain context.  
- **History Persistence**:  
  - Save chat logs and summaries to a JSON file in a directory (e.g., `mediation_history`).  
  - File naming format: `session_<timestamp>.json` (e.g., `session_20231001_153000.json`).  

**1.4 Text-to-Speech (TTS)**  
- **Mediator Response TTS**:  
  - Use `kokoro-onnx` to convert the mediator’s text response to speech.  
  - Play audio automatically after the mediator’s response is displayed.  
  - Adjustable speech rate (default: 180 words/minute).  

**1.5 Speech-to-Text (STT)**  
- **Real-Time Voice Input**:  
  - Users can click a "Listen" button to enable microphone input.  
  - Use `speech_recognition` library for Google Web Speech API integration.  
  - Error handling for unrecognized speech or network issues.  

**1.6 Status Feedback**  
- **Loading Indicators**:  
  - Display animated status updates (e.g., "Mediator is thinking...", "Generating response...").  
  - Block user input during LLM processing or TTS playback.  

**1.7 Handout Generation**  
- **Session Summary Handout**:  
  - Compile key points from the mediator’s summaries, advice, observations and chat history.  
  - Include emotional states, issues identified, and suggestions for the next session.  
  - Provide a "Generate Handout" button in a dedicated tab to downlaod the couple's takehome assignment as text.  
---

#### **2. Technical Requirements**
**2.1 LLM Integration**  
- **Ollama Model**: Use the specified model `llama3.2:1b` for chat and summarization.  
- **System Prompt**: The mediator must adhere to a neutral, empathetic tone as defined in `SYSTEM_PROMPT`.  
**2.2 Thread Management**  
- **Asynchronous Processing**:  
  - Run LLM, TTS, and STT operations in background threads to prevent UI freezing.  
  - Use  thread-safe communication 

**2.3 UI Components**  
- **Gradio GUI**:  
  - Chat display area with scroll-to-bottom functionality.  
  - Separate tabs for "Chat" and "Notes & Handout".  
  - Status bar to show processing status (e.g., "Ready", "Summarizing...").  

**2.4 Session Management**  
- **Auto-Save**:  
  - Persist chat history and summaries to disk on close (or send).  

**2.5 Error Handling**  
- **Graceful Degradation**:  
  - Display error messages for LLM timeouts, TTS failures, or STT recognition issues.  
  - Retry mechanisms for network-dependent features (e.g., STT).  

#### **3. User Experience (UX) Requirements**
**3.1 Input Modes**  
- **Text Input**: Users type messages and click "Send" to submit.  
- **Voice Input**:  
  - Click "Listen" to start recording.  
  - Visual feedback (e.g., "Listening...") during voice capture.  

**3.2 Responsive Design**  
- **Layout**:  
  - Chat display occupies 80% vertical space, with input fields below.  
  - Equal horizontal split for User A and B input sections.  
  - `Enter` key sends text messages.  
  - Libraries: `ollama`, `kokoro-onnx`, `speech_recognition`, `gradio`.  
  Assistant B

1. Executive Summary
This document outlines the requirements for the development of the "Relationship Mediator LLM Application." The primary goal is to create a desktop or web-based application that acts as a neutral third party to help two users (e.g., a couple) communicate more effectively. The application will leverage a local Large Language Model (LLM) via Ollama for mediation, provide speech-to-text (STT) and text-to-speech (TTS) capabilities for accessibility, and manage session history to ensure continuity and context awareness. The final product will also generate a "take-home" summary for the users to reflect on.

This is a greenfield project. The new team will build the application from the ground up based on these specifications.

2. Core User Roles
User A & User B (The Participants): The primary users of the application. They interact with the app by typing or speaking their messages.
The Mediator (LLM): The AI-driven core of the application, responsible for generating neutral, empathetic, and constructive responses.
3. High-Level Epics (Core Feature Groups)
The project is broken down into the following key feature areas (Epics):

Epic 1: Core Chat Interface & Interaction
Epic 2: LLM-Powered Mediation & Context Management
Epic 3: Voice-to-Text & Text-to-Speech Integration
Epic 4: Session History & Data Persistence
Epic 5: Session Review & Handout Generation
4. Detailed Functional Requirements (FR)
Epic 1: Core Chat Interface & Interaction
FR-1.1: Dual User Input: The UI must provide two separate and clearly labeled input areas, one for "User A" and one for "User B". Each user must have their own "Send" button.
FR-1.2: Message Bubble Styling: The chat display area must render messages in a "bubble" style to visually distinguish between speakers.
User A's messages: Right-aligned, distinct color (e.g., blue background, white text).
User B's messages: Left-aligned, distinct color (e.g., green background, white text).
Mediator's messages: Center-aligned, neutral color (e.g., light grey background, dark text).
System messages/Summaries: Center-aligned, styled distinctly to indicate a non-conversational event (e.g., italicized or in a different container).
FR-1.3: Asynchronous UI: The user interface must remain responsive at all times. LLM processing, TTS, and STT must run in background threads to prevent the UI from freezing.
FR-1.4: Real-time Status Indicator: A status bar or text element must provide real-time feedback to the users about the application's state. Required statuses include:
Ready
Listening... (during STT)
Processing audio...
Mediator is thinking... / Generating response...
History length threshold reached, summarizing...
Mediator is speaking...
Error: [Error message]
FR-1.5: UI Framework: The application shall be built using Gradio, as it provides a robust framework for ML application demos and web deployment.
Epic 2: LLM-Powered Mediation & Context Management
FR-2.1: LLM Integration: The application must integrate with a local Ollama instance. The specific model (e.g., llama3.2:1b) shall be configurable.
FR-2.2: Mediator Persona Prompt: On initialization, the LLM's context must be primed with a system prompt to define its role and behavior. The prompt is:
"You are a neutral relationship mediator helping two people, User A and User B, communicate better. Listen carefully to their messages. After each message, provide a balanced, empathetic, and constructive response that helps them understand each other, reflect on their perspective, or find common ground. Avoid taking sides. Summarize feelings and needs you hear. Assist in resolving tension by offering understanding, reframing, and kind suggestions. Only respond after a user has sent their message."

FR-2.3: Context Window Management via Summarization: To manage context length and cost, the application will automatically summarize the conversation history.
Trigger Condition: Summarization shall occur when the number of message pairs (user message + mediator response) reaches a threshold of 10 (SUMMARY_THRESHOLD).
Summarization Prompt: The summarization call to the LLM will use the full current history appended with the following user prompt:
"You are a skilled mediator and counselor. Analyze the above conversation history and note any emotional states expressed by User A and by User B, key issues in their relationship, any previous suggestions you, the mediator, have made, and concisely summarize key points. Your summary will replace the older conversation history to help you recall the context for future mediation. Provide ONLY the summary text, do not add any other conversational text or act as the mediator in this specific response."

Context Reconstruction: After