Day 7: Building a Frontend Truth Meter UI #progressbar #emotionUX

SEO Title: Day 7: Building a Frontend Truth Meter UI #progressbar #emotionUX
Focus Keyphrase: AI lie detector
Meta Description: Learn how to build a dynamic frontend for your AI lie detector app with a Truth Score meter, progress bar, and real-time visual feedback.

Making the AI Lie Detector User-Friendly

Your AI lie detector backend now calculates a powerful Truth Score. Today, weโ€™ll create a simple but effective frontend to display:

  • ๐ŸŽ™๏ธ The transcribed speech
  • ๐Ÿง  GPT semantic analysis
  • ๐ŸŽง Vocal emotion score
  • โœ… Final Truth Score as a progress bar

Step 1: Update frontend/index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>AI Lie Detector</title>
  <style>
    #truthBar {
      width: 100%;
      background: #eee;
      height: 30px;
      margin-top: 20px;
      border-radius: 15px;
      overflow: hidden;
    }
    #truthFill {
      height: 100%;
      width: 0%;
      background: green;
      text-align: center;
      color: white;
      line-height: 30px;
    }
  </style>
</head>
<body>
  <h2>๐ŸŽ™๏ธ AI Lie Detector</h2>
  <button id="startBtn">Start Recording</button>
  <button id="stopBtn" disabled>Stop Recording</button>

  <div id="result" style="margin-top:20px"></div>
  <div id="truthBar">
    <div id="truthFill">0%</div>
  </div>

  <script src="recorder.js"></script>
</body>
</html>

Step 2: Update frontend/recorder.js


let mediaRecorder;
let audioChunks = [];

document.getElementById("startBtn").onclick = async () => {
  const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
  mediaRecorder = new MediaRecorder(stream);
  mediaRecorder.start();
  audioChunks = [];

  mediaRecorder.ondataavailable = event => {
    audioChunks.push(event.data);
  };

  mediaRecorder.onstop = async () => {
    const audioBlob = new Blob(audioChunks, { type: "audio/webm" });
    const formData = new FormData();
    formData.append("audio", audioBlob);

    const response = await fetch("http://localhost:5000/api/voice", {
      method: "POST",
      body: formData,
    });
    const data = await response.json();

    document.getElementById("result").innerHTML = `
      &lt;b&gt;Transcript:&lt;/b&gt; ${data.transcript}&lt;br&gt;
      &lt;b&gt;GPT Analysis:&lt;/b&gt; ${data.gpt_analysis}&lt;br&gt;
      &lt;b&gt;Emotion Score:&lt;/b&gt; ${data.emotion_score}&lt;br&gt;
      &lt;b&gt;Truth Score:&lt;/b&gt; ${data.truth_score}%
    `;

    const truthFill = document.getElementById("truthFill");
    truthFill.style.width = data.truth_score + "%";
    truthFill.innerText = data.truth_score + "%";

    if (data.truth_score &gt; 70) {
      truthFill.style.background = "green";
    } else if (data.truth_score &gt; 40) {
      truthFill.style.background = "orange";
    } else {
      truthFill.style.background = "red";
    }
  };

  document.getElementById("stopBtn").disabled = false;
};

document.getElementById("stopBtn").onclick = () => {
  mediaRecorder.stop();
  document.getElementById("stopBtn").disabled = true;
};

What Happens Now?

After recording and analyzing a user’s voice:

  • ๐Ÿ“ The statement is shown
  • ๐Ÿง  GPT analysis explanation is shown
  • ๐ŸŽง Emotion score is shown
  • โœ… Truth Score fills a colored bar in real time!

Why Visual Feedback Matters

Users can instantly see their truth probability, making the AI lie detector interactive, educational, and a bit dramatic โ€” just like a real interrogation tool!

Coming Tomorrow

In Day 8: Fine-Tuning Truth Detection with Thresholds #smartdetection #uximprovement, weโ€™ll improve the sensitivity, thresholds, and balance between emotion and semantics for different real-world use cases.


Tags: #AIUX #ProgressBarUI #LieDetection #VoiceUX

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.