Skip to content

Aditya-Yan/SentimentRadar

Repository files navigation

Sentiment Radar — T-Mobile Customer Happiness Index

A real-time dashboard that displays customer happiness levels by region and uses an NVIDIA Nemotron multi-step agent to diagnose issues and auto-generate resolution recommendations.

Features

  • 🗺️ Interactive Map Visualization: Heatmap showing customer happiness scores by US region
  • 📊 Real-time Sentiment Analysis: Aggregated sentiment data from multiple sources
  • 🤖 NVIDIA Nemotron Agent: Multi-step workflow for diagnosing issues and generating recommendations
  • 📱 Responsive Dashboard: Dark, minimal UI with real-time updates
  • 🔄 Auto-refresh: Data updates every 30 seconds
  • 📈 Trend Analysis: Track positive and negative sentiment spikes

Tech Stack

  • Frontend: Next.js 14 + React + TypeScript
  • Styling: TailwindCSS
  • Map: Leaflet.js + React-Leaflet
  • Backend: Next.js API Routes
  • Database: Supabase (PostgreSQL)
  • LLM Agent: NVIDIA Nemotron (simulated with rule-based logic)
  • Sentiment Analysis: HuggingFace API (with fallback)

Prerequisites

  • Node.js 18+ and npm
  • Supabase account and project
  • (Optional) HuggingFace API key for sentiment analysis
  • (Optional) NVIDIA API key for Nemotron integration

Setup

  1. Clone and install dependencies:

    npm install
  2. Set up environment variables:

    cp .env.local.example .env.local

    Edit .env.local and add your credentials:

    NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
    NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
    SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
    
    # Optional
    HUGGINGFACE_API_KEY=your_huggingface_api_key
    NVIDIA_API_KEY=your_nvidia_api_key
    NVIDIA_BASE_URL=https://integrate.api.nvidia.com/v1
  3. Set up Supabase database:

    • Create a new Supabase project
    • Run the migration script from supabase/migrations/001_initial_schema.sql in your Supabase SQL editor
    • Or use Supabase CLI: supabase db push
  4. Seed the database (optional):

    npm run seed
  5. Run the development server:

    npm run dev
  6. Open your browser: Navigate to http://localhost:3000

Project Structure

SentimentRadar/
├── app/                    # Next.js app directory
│   ├── api/               # API routes
│   │   ├── diagnose/      # Nemotron agent endpoint
│   │   ├── snapshots/     # Sentiment data endpoint
│   │   └── publish-slack/ # Slack integration (simulated)
│   ├── globals.css        # Global styles
│   ├── layout.tsx         # Root layout
│   └── page.tsx           # Main dashboard page
├── components/            # React components
│   ├── Dashboard.tsx      # Main dashboard component
│   ├── HappinessMap.tsx   # Map visualization
│   ├── Sidebar.tsx        # Sentiment trends sidebar
│   └── DiagnosisPanel.tsx # Diagnosis results modal
├── lib/                   # Utility libraries
│   ├── supabase.ts        # Supabase client setup
│   ├── sentiment.ts       # Sentiment analysis service
│   └── nemotron-agent.ts  # Nemotron agent workflow
├── scripts/               # Utility scripts
│   └── seed.ts            # Database seeding script
└── supabase/              # Database migrations
    └── migrations/
        └── 001_initial_schema.sql

Database Schema

sentiment_snapshots

  • id (uuid, primary key)
  • region (text)
  • happiness_score (float, 0-100)
  • sentiment_summary (text)
  • outage_level (integer, 0-100)
  • created_at (timestamp)

resolution_logs

  • id (uuid, primary key)
  • region (text)
  • cause (text)
  • internal_message (text)
  • customer_message (text)
  • created_at (timestamp)

Usage

Running Diagnosis

  1. Click on any region marker on the map
  2. Click "Run Diagnosis" in the popup
  3. The Nemotron agent will:
    • Retrieve latest sentiment data
    • Analyze trends
    • Identify root causes
    • Generate internal and customer-facing messages
  4. Review the results in the diagnosis panel
  5. Optionally publish to Slack (simulated)

Viewing Trends

  • The sidebar shows:
    • Overall happiness score
    • Top 5 negative sentiment spikes
    • Top 5 positive moments
  • Data refreshes automatically every 30 seconds
  • Click the refresh button to manually update

NVIDIA Nemotron Agent Workflow

The agent implements a 5-step workflow:

  1. Retrieve Data: Fetches latest sentiment and outage data from Supabase
  2. Analyze Trend: Determines if happiness is rising, falling, or stable
  3. Identify Cause: If happiness drops below threshold, identifies probable causes
  4. Generate Internal Message: Creates detailed resolution message for internal teams
  5. Generate Customer Message: Creates customer-friendly status update

Customization

Adding Real NVIDIA Nemotron Integration

Edit lib/nemotron-agent.ts and uncomment the callNemotronAPI function implementation. Replace the simulated responses with actual API calls:

const response = await fetch(`${process.env.NVIDIA_BASE_URL}/chat/completions`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.NVIDIA_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    model: 'nemotron-4-340b-instruct',
    messages: [
      { role: 'system', content: systemPrompt },
      { role: 'user', content: prompt }
    ],
  }),
})

Adding Real Data Sources

To integrate real Twitter/X, Reddit, or outage data:

  1. Create new API routes in app/api/
  2. Implement data fetching logic
  3. Use lib/sentiment.ts to analyze sentiment
  4. Insert results into sentiment_snapshots table

Development

# Run development server
npm run dev

# Build for production
npm run build

# Start production server
npm start

# Run linter
npm run lint

# Seed database
npm run seed

Environment Variables

Variable Required Description
NEXT_PUBLIC_SUPABASE_URL Yes Supabase project URL
NEXT_PUBLIC_SUPABASE_ANON_KEY Yes Supabase anonymous key
SUPABASE_SERVICE_ROLE_KEY Yes Supabase service role key (for admin operations)
HUGGINGFACE_API_KEY No HuggingFace API key for sentiment analysis
NVIDIA_API_KEY No NVIDIA API key for Nemotron
NVIDIA_BASE_URL No NVIDIA API base URL

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors