<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sachinthaheshan on Medium]]></title>
        <description><![CDATA[Stories by Sachinthaheshan on Medium]]></description>
        <link>https://medium.com/@sachinthaheshan94?source=rss-8d34c50626c5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*4xSToqRGP6sedTW6</url>
            <title>Stories by Sachinthaheshan on Medium</title>
            <link>https://medium.com/@sachinthaheshan94?source=rss-8d34c50626c5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 20:46:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sachinthaheshan94/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[4-bit universal decimal to SSD (Seven-Segment Display) counter.]]></title>
            <link>https://medium.com/@sachinthaheshan94/4-bit-universal-decimal-to-ssd-seven-segment-display-counter-e19f720d735d?source=rss-8d34c50626c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e19f720d735d</guid>
            <category><![CDATA[4-bit-counter]]></category>
            <category><![CDATA[vhdl]]></category>
            <category><![CDATA[counter]]></category>
            <category><![CDATA[assessment]]></category>
            <category><![CDATA[seven-segment-display]]></category>
            <dc:creator><![CDATA[Sachinthaheshan]]></dc:creator>
            <pubDate>Sat, 21 Mar 2026 04:16:30 GMT</pubDate>
            <atom:updated>2026-03-21T04:24:43.110Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*K88o18C2wTJ6Be7dlAfcZA.jpeg" /><figcaption>External View of the System</figcaption></figure><h3>Introduction</h3><p>Design and implement a 4-bit universal decimal counter using VHDL, which will display the output on a seven-segment display (SSD). This type of counter is commonly used in digital systems for counting purposes where the result needs to be easily read by humans. The goal of this project is to showcase skills in VHDL design, simulation, and the application of advanced digital design tools.</p><h4><strong><em>Design Brief</em></strong></h4><p>The designed 4-bit universal decimal counter must fulfil the following key functionalities.</p><p>· Synchronous Parallel Load (PL): Allows the counter to load a specific value synchronously.</p><p>· Parallel Data Input (PD3, PD2, PD1, PD0): Inputs for parallel data to be loaded into the counter.</p><p>· SSD Outputs (S6, S5, S4, S3, S2, S1, S0): Outputs corresponding to the segments A through G of the seven-segment display.</p><p>· Asynchronous Reset Input (RST): An input that resets the counter asynchronously, setting the SSD output to zero.</p><p>· Count Direction (CD): An input that determines the counting direction, enabling the counter to count up or down.</p><p>· Synchronising Clock Input (CLK): A clock signal that synchronises the counting process.</p><p>This design requires careful consideration of digital design principles and VHDL programming to ensure accurate and efficient counter operation. The report will cover the entire design process, from the initial design brief to the final simulation results, providing a comprehensive overview of the counter’s development and functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*eSaIG-e3HSTcmyIF5lPWxw.png" /><figcaption>function table and design</figcaption></figure><h3>Solution Explanation</h3><p><strong>External View of the 4-bit universal decimal to SSD (Seven-Segment Display) counter.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*K88o18C2wTJ6Be7dlAfcZA.jpeg" /><figcaption>External View of the System</figcaption></figure><p>The designed SSD counter has five inputs and one output. When designing this counter, four states are used: IDEAL, A, B, and C. The IDEAL state is the starting state. If the input RST=0 is given in any state, the state changes to IDEAL. State A is the Up-counter state, State B is the Down-counter state, and State C is the free state. In State C, the counter can transition to any state freely, and any number can be output given the input for PD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*R2UBgPFk_0egVPCCFPwFcg.png" /><figcaption>State Diagram of the System</figcaption></figure><h3><strong>VHDL Code Listing</strong></h3><p><strong>VHDL Implementation</strong></p><p>library IEEE;<br>use IEEE.STD_LOGIC_1164.ALL;<br>use IEEE.STD_LOGIC_ARITH.ALL;<br>use IEEE.STD_LOGIC_UNSIGNED.ALL;</p><p>entity test01 is</p><p>port (</p><p>CLK: in STD_LOGIC; — clock signal<br>RST: in STD_LOGIC; — Asynchronous Reset Input<br>PL: in STD_LOGIC; — Synchronous Parallel Load<br>CD: in STD_LOGIC; — Count direction(Up/Down)<br>PD: in STD_LOGIC_VECTOR (3 downto 0); — Parallel Data Input<br>SSD_OUT: out STD_LOGIC_VECTOR (6 downto 0) — SSD outputs seven segment display</p><p>);</p><p>end test01;</p><p>architecture Behavioral of test01 is</p><p>type SSD_FSM is (IDEAL, A, B, C);</p><p>signal Count: STD_LOGIC_VECTOR(3 downto 0) := “0000”; — 4-bit count number</p><p>signal current_state, next_state: SSD_FSM := IDEAL;</p><p>begin</p><p>Process(CLK, RST)</p><p>begin</p><p>if RST = ‘0’ then</p><p>current_state &lt;= IDEAL;</p><p>elsif rising_edge(CLK) then</p><p>current_state &lt;= next_state;</p><p>end if;</p><p>end process;</p><p>Process(current_state, PL, CD, PD)</p><p>begin</p><p>if RST = ‘1’ then</p><p>case current_state is</p><p>— Ideal State</p><p>when IDEAL =&gt;</p><p>if PL = ‘0’ and CD = ‘1’ then</p><p>next_state &lt;= A;</p><p>elsif PL = ‘0’ and CD = ‘0’ then</p><p>next_state &lt;= B;</p><p>elsif PL = ‘1’ then</p><p>Count &lt;= PD;</p><p>next_state &lt;= C;</p><p>end if;</p><p>— Up Counter</p><p>when A =&gt;</p><p>if PL=’0&#39; and CD = ‘1’ then</p><p>if Count = “1001” then</p><p>Count &lt;= “0000”;</p><p>else</p><p>Count &lt;= Count + 1;</p><p>end if;</p><p>next_state &lt;= A;</p><p>elsif PL = ‘0’ and CD = ‘0’ then</p><p>if Count = “0000” then</p><p>Count &lt;= “1001”;</p><p>else</p><p>next_state &lt;= B;</p><p>end if;</p><p>elsif PL = ‘1’ then</p><p>Count &lt;= PD;</p><p>next_state &lt;= C;</p><p>end if;</p><p>— Down Counter</p><p>when B =&gt;</p><p>if PL = ‘0’ and CD = ‘0’ then</p><p>if Count = “0000” then</p><p>Count &lt;= “1001”;</p><p>else</p><p>Count &lt;= Count — 1;</p><p>end if;</p><p>next_state &lt;= B;</p><p>elsif PL = ‘0’ and CD = ‘1’ then</p><p>if Count = “1001” then</p><p>Count &lt;= “0000”;</p><p>else</p><p>next_state &lt;= A;</p><p>end if;</p><p>elsif PL = ‘1’ then</p><p>Count &lt;= PD;</p><p>next_state &lt;= C;</p><p>end if;</p><p>— Synchronous Data Load</p><p>when C =&gt;</p><p>if PL = ‘1’ then</p><p>Count &lt;= PD;</p><p>next_state &lt;= C;</p><p>elsif PL = ‘0’ and CD = ‘1’ then</p><p>if Count = “1001” then</p><p>Count &lt;= “0000”;</p><p>else</p><p>next_state &lt;= A;</p><p>end if;</p><p>elsif PL = ‘0’ and CD = ‘0’ then</p><p>if Count = “0000” then</p><p>Count &lt;= “1001”;</p><p>else</p><p>next_state &lt;= B;</p><p>end if;</p><p>end if;</p><p>end case;</p><p>else</p><p>next_state &lt;= IDEAL;</p><p>Count &lt;= “0000”;</p><p>end if;</p><p>end process;</p><p>— Related Count values for SSD_OUT</p><p>Process(Count)</p><p>begin</p><p>case Count is</p><p>when “0000” =&gt; SSD_OUT &lt;= “0111111”; — 0</p><p>when “0001” =&gt; SSD_OUT &lt;= “0000110”; — 1</p><p>when “0010” =&gt; SSD_OUT &lt;= “1011011”; — 2</p><p>when “0011” =&gt; SSD_OUT &lt;= “1001111”; — 3</p><p>when “0100” =&gt; SSD_OUT &lt;= “1100110”; — 4</p><p>when “0101” =&gt; SSD_OUT &lt;= “1101101”; — 5</p><p>when “0110” =&gt; SSD_OUT &lt;= “1111101”; — 6</p><p>when “0111” =&gt; SSD_OUT &lt;= “0000111”; — 7</p><p>when “1000” =&gt; SSD_OUT &lt;= “1111111”; — 8</p><p>when “1001” =&gt; SSD_OUT &lt;= “1100111”; — 9</p><p>when others =&gt; SSD_OUT &lt;= “0000000”; — Blank or error state</p><p>end case;</p><p>end process;</p><p>end Behavioral;</p><p><strong>Testbench Code</strong></p><p>LIBRARY ieee;</p><p>USE ieee.std_logic_1164.ALL;</p><p>ENTITY main_tb IS</p><p>END main_tb;</p><p>ARCHITECTURE behavior OF main_tb IS</p><p>— Component Declaration for the Unit Under Test (UUT)</p><p>COMPONENT test01</p><p>PORT(</p><p>CLK : IN std_logic;</p><p>RST : IN std_logic;</p><p>PL : IN std_logic;</p><p>CD : IN std_logic;</p><p>PD : IN std_logic_vector(3 downto 0);</p><p>SSD_OUT : OUT std_logic_vector(6 downto 0)</p><p>);</p><p>END COMPONENT;</p><p>— Inputs</p><p>signal CLK : std_logic := ‘0’;</p><p>signal RST : std_logic := ‘0’;</p><p>signal PL : std_logic := ‘0’;</p><p>signal CD : std_logic := ‘0’;</p><p>signal PD : std_logic_vector(3 downto 0) := (others =&gt; ‘0’);</p><p>— Outputs</p><p>signal SSD_OUT : std_logic_vector(6 downto 0);</p><p>— Clock period definitions</p><p>constant CLK_period : time := 10 ns;</p><p>BEGIN</p><p>— Instantiate the Unit Under Test (UUT)</p><p>uut: test01 PORT MAP (</p><p>CLK =&gt; CLK,</p><p>RST =&gt; RST,</p><p>PL =&gt; PL,</p><p>CD =&gt; CD,</p><p>PD =&gt; PD,</p><p>SSD_OUT =&gt; SSD_OUT</p><p>);</p><p>— Clock process definitions</p><p>CLK_process : process</p><p>begin</p><p>while true loop</p><p>CLK &lt;= ‘0’;</p><p>wait for CLK_period/2;</p><p>CLK &lt;= ‘1’;</p><p>wait for CLK_period/2;</p><p>end loop;</p><p>end process;</p><p>— Stimulus process</p><p>stim_proc: process</p><p>begin</p><p>— Hold reset state for 100 ns.</p><p>RST &lt;= ‘0’;</p><p>PL &lt;= ‘0’;</p><p>CD &lt;= ‘0’;</p><p>wait for 100 ns;</p><p>— Release reset</p><p>RST &lt;= ‘1’;</p><p>wait for CLK_period*10;</p><p>— Test counting up (counting up 10 clock cycles)</p><p>PL &lt;= ‘0’;</p><p>CD &lt;= ‘1’;</p><p>wait for CLK_period*10;</p><p>— Test counting down (counting down 10 clock cycles)</p><p>PL &lt;= ‘0’;</p><p>CD &lt;= ‘0’;</p><p>wait for CLK_period*10;</p><p>— Test Parallel load with value 3</p><p>PL &lt;= ‘1’;</p><p>PD &lt;= “0011”; — Load 3</p><p>wait for CLK_period*10;</p><p>PL &lt;= ‘0’; — Clear PL to allow counting</p><p>wait for CLK_period*10;</p><p>— Test Parallel load with value 6</p><p>PL &lt;= ‘1’;</p><p>PD &lt;= “0110”; — Load 6</p><p>wait for CLK_period*10;</p><p>PL &lt;= ‘0’; — Clear PL to allow counting</p><p>wait for CLK_period*10;</p><p>— Test counting up again (counting up 10 clock cycles)</p><p>PL &lt;= ‘0’;</p><p>CD &lt;= ‘1’;</p><p>wait for CLK_period*10;</p><p>— Test counting down again (counting down 10 clock cycles)</p><p>PL &lt;= ‘0’;</p><p>CD &lt;= ‘0’;</p><p>wait for CLK_period*10;</p><p>— Test Reset</p><p>RST &lt;= ‘0’;</p><p>wait for 100 ns;</p><p>RST &lt;= ‘1’;</p><p>wait;</p><p>end process;</p><p>END;</p><h4>In this Testbench code test following steps</h4><p>· Hold reset state for 100 ns.<br>· Release reset.<br>· Test counting up (counting up 10 clock cycles).<br>· Test counting down (counting down 10 clock cycles).<br>· Test Parallel load with value 3.<br>· Test Parallel load with value 6.<br>· Test counting up again (counting up 10 clock cycles).<br>· Test counting down again (counting down 10 clock cycles).<br>· Test Reset.</p><h3>Graphical Testbench Screenshot</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nybQRHMTfGAo4yPc1t1ShQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hrzzlso0KwlEAv7iQ-HW8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mdorzBDJpNfL7ZzqeAZrJg.png" /><figcaption>Simulated results</figcaption></figure><h3>Simulation Results</h3><p>The simulation results for the 4-bit universal decimal to Seven-Segment Display (SSD) counter are presented to demonstrate the functionality and correctness of the VHDL design. The results highlight several key operational modes and transitions of the counter, including counting up, counting down, parallel loading, and asynchronous resetting. Here’s a detailed explanation of the simulation results.</p><p><strong>Counting Up</strong></p><p>The counter begins in the idle state and transitions to the up-counting state when the count direction (CD) input is set to ‘1’. With each rising edge of the clock signal (CLK), the counter increments its value by one. The SSD outputs (SSD_OUT) display the corresponding decimal digit on the seven-segment display, ranging from 0 to 9. When the counter reaches the value ‘9’, it wraps around to ‘0’.</p><p><strong>Counting Down</strong></p><p>The counter transitions to the down-counting state when the count direction (CD) input is set to ‘0’. With each rising edge of the clock signal (CLK), the counter decrements its value by one. The SSD outputs (SSD_OUT) display the corresponding decimal digit on the seven-segment display, ranging from 9 to 0. When the counter reaches the value ‘0’, it wrapsaround to ‘9’.</p><p><strong>Parallel Load</strong></p><p>When the parallel load (PL) input is set to ‘1’, the counter transitions to the parallel load state. The value specified by the parallel data input (PD) is then loaded into the counter, and the SSD outputs (SSD_OUT) immediately display the loaded value on the seven-segment display. After loading, the counter can resume counting up or down based on the count direction (CD) input.</p><p><strong>Asynchronous Reset</strong></p><p>The counter transitions to the idle state when the asynchronous reset (RST) input is set to ‘0’. The counter value is reset to ‘0’, and the SSD outputs (SSD_OUT) display ‘0’ on the seven-segment display. The reset operation is immediate and independent of the clock signal (CLK).<br>The simulation results confirm that the VHDL code works correctly, showing that the counter behaves as expected under different conditions. The counter accurately counts up and down, properly loads data, and resets when needed. The seven-segment display shows the correct numbers for each counter value, proving that the counter and display logic are well-integrated and functioning as intended.</p><h3>Conclusions</h3><p>This design is crucial for various industrial applications. Seven-segment displays are widely used to provide a user-friendly numeric display in devices such as instrumentation panels, measurement devices, and digital clocks. A 4-bit counter can efficiently represent decimal numbers from 0 to 9, making it suitable for applications requiring single-digit numeric displays. This is particularly beneficial in embedded systems where space and power are limited. In industrial environments, real-time data display is essential for monitoring and control. A 4-bit counter driving a seven-segment display can offer immediate visual feedback for processes such as counting, timing, and measuring.<br>During the design process, several challenges were encountered. Errors in the state transition diagram can cause the counter to skip states, become stuck, or transition incorrectly. Misinterpretation of binary to decimal encoding can lead to incorrect digit representation. Additionally, bugs in the VHDL code that controls the counter and display logic can result in incorrect counting or display.<br>The design can be improved by extending it to multiple seven-segment displays, which would enhance its utility in industrial applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e19f720d735d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Built a Serverless “Smart Sentiment & Content Analyser” on AWS -Zero cost.]]></title>
            <link>https://medium.com/@sachinthaheshan94/i-built-a-serverless-smart-sentiment-content-analyser-on-aws-zero-cost-0a3bc5edd280?source=rss-8d34c50626c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/0a3bc5edd280</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[sentiment-analysis]]></category>
            <category><![CDATA[aws-s3]]></category>
            <category><![CDATA[amazon-comprehend]]></category>
            <dc:creator><![CDATA[Sachinthaheshan]]></dc:creator>
            <pubDate>Mon, 29 Sep 2025 16:31:49 GMT</pubDate>
            <atom:updated>2025-09-29T16:31:49.411Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u7GCRlPUimyF-3oe0zZt0A.png" /><figcaption>Frontend of the webapp</figcaption></figure><p>You know that feeling when you’re sitting in your AI class, learning about natural language processing, and everything seems so… theoretical? The professor is talking about sentiment analysis, named entity recognition, and all these fancy terms that sound like they belong in expensive research labs.Well, I was that student until last weekend when I decided to bridge the gap between classroom theory and real-world application. And the best part? I did it without the one thing students have least of money.</p><p>I stood up a tiny web app that analyzes any text for <strong>sentiment</strong>, <strong>key phrases</strong>, and <strong>named entities</strong> using <strong>Amazon Comprehend</strong>, <strong>AWS Lambda (Python)</strong>, <strong>API Gateway</strong>, and a static site on <strong>Amazon S3</strong>. It’s fully serverless, free-tier friendly, and a great hands-on intro to AWS AI services.</p><h3>What I Actually Built</h3><p>Let me break down what this “Smart Sentiment &amp; Content Analyser” actually does in student-friendly terms:</p><p>Imagine you could give this app any piece of text — like your frustrated tweet about finals, a product review you’re writing, or even your essay draft and it would tell you:</p><ul><li>The Vibe: Is this text happy, sad, angry, or mixed? 😊 😐 😠</li><li>Main Points: What are the key topics being discussed?</li><li>Who/What/Where: Can it spot names, companies, places?</li></ul><p>So if I input: <em>“I love studying at Stanford University, but the coffee at their cafeteria is terrible.”</em></p><p>The app would output:</p><ul><li>Vibe: Mixed feelings (because there’s both love and hate)</li><li>Main Points: “studying”, “Stanford University”, “coffee”, “cafeteria”</li><li>Entities: “Stanford University” (it’s an organization)</li></ul><p>See? Suddenly those boring NLP concepts from class make actual sense!</p><h3>Why This Project Doesn’t Suck for Beginners</h3><p>I’ve tried following tutorials before that promise “beginner-friendly” projects but then assume you have years of cloud experience. This one’s different because.</p><p>Amazon S3 — The Digital Backpack</p><ul><li>What it is: Simple Storage Service (fancy name for cloud file storage).</li><li>Student analogy: Think of it like Google Drive, but programmable.</li><li>Why we use it: To store our website files (HTML, CSS, JS) because it’s dead simple and crazy reliable.</li></ul><p>AWS Lambda — The Magical Helper</p><ul><li>What it is: Serverless compute service (translation: code that runs only when needed).</li><li>Student analogy: Like having a friend who only shows up when you text them, does exactly what you ask, then disappears.</li><li>Why we use it: No servers to manage = no headaches = perfect for students.</li></ul><p>API Gateway — The Receptionist</p><ul><li>What it is: Manages API endpoints (fancy term for web addresses that accept requests).</li><li>Student analogy: Like a building receptionist who directs visitors to the right rooms.</li><li>Why we use it: It safely connects our website to our Lambda function.</li></ul><p>Amazon Comprehend — The Brain</p><ul><li>What it is: AI service for understanding text.</li><li>Student analogy: That friend who’s amazing at reading between the lines.</li><li>Why we use it: Pre-trained AI means we don’t need to build ML models from scratch.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*i7ofiBxTdRH_-q5271p0IQ.jpeg" /><figcaption>System AWS Architecture</figcaption></figure><h3>Moment #1: When I Realised Serverless Isn’t Just Buzzword Bingo</h3><p>In class, we learn about servers, virtual machines, and all that infrastructure stuff. But with Lambda, I wrote my Python code, uploaded it, and it just worked. No “ssh-ing” into machines, no installing dependencies, no worrying about scaling.</p><p>It hit me: this is why cloud computing is a game-changer. We can focus on writing code that solves problems, not on managing infrastructure.</p><h3>Moment #2: When Three Lines of Code Did What Used to Take Semesters</h3><p>Here’s the Python code that blew my mind:</p><pre># This is literally all it takes to analyze text sentiment<br>sentiment = comprehend.detect_sentiment(Text=my_text)<br><br># And these two lines get key phrases and entities<br>phrases = comprehend.detect_key_phrases(Text=my_text)<br>entities = comprehend.detect_entities(Text=my_text)</pre><p>In my NLP course, we spent weeks learning how to build sentiment analysis models. Don’t get me wrong — understanding the theory is important. But seeing how accessible these capabilities have become was genuinely exciting.</p><h3>Moment #3: When I Understood How Everything Connects</h3><p>This was the biggest lightbulb moment. Each AWS service is like a specialized team member:</p><ul><li>S3 is the front desk: “Here’s our website, welcome!”</li><li>API Gateway is the coordinator: “You have a request? Let me route it to the right place”</li><li>Lambda is the worker: “I got your text, let me process it”</li><li>Comprehend is the expert: “I’m really good at understanding language, let me help”</li></ul><p>Seeing how they pass data to each other like a well-coordinated team made distributed systems feel less abstract.</p><h3>Codes</h3><p>index.html</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;utf-8&quot; /&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot; /&gt;<br>  &lt;title&gt;Smart Sentiment &amp; Content Analyzer&lt;/title&gt;<br><br>  &lt;!-- Optional: pretty font; safe to remove if you don&#39;t want external calls --&gt;<br>  &lt;link href=&quot;https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt;<br><br>  &lt;style&gt;<br>    :root{<br>      --bg: #0b1020;<br>      --panel: #11182b;<br>      --text: #e6ecff;<br>      --muted:#93a0c8;<br>      --brand:#7c9bff;<br>      --accent:#46e0b3;<br>      --danger:#ff6b6b;<br>      --chip:#1a2442;<br>      --border:#223058;<br>      --shadow: 0 10px 30px rgba(0,0,0,.35);<br>    }<br>    /* light mode tweaks will invert these via .light class on body */<br>    body.light{<br>      --bg:#f6f8ff;<br>      --panel:#ffffff;<br>      --text:#0b1020;<br>      --muted:#4b597d;<br>      --brand:#4b6bff;<br>      --accent:#0bbf8a;<br>      --danger:#e35656;<br>      --chip:#eef2ff;<br>      --border:#e5e8f5;<br>      --shadow: 0 10px 30px rgba(16,26,71,.08);<br>    }<br><br>    *{box-sizing:border-box}<br>    html,body{height:100%}<br>    body{<br>      margin:0;<br>      font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, &quot;Helvetica Neue&quot;, Arial, &quot;Noto Sans&quot;, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;;<br>      background: radial-gradient(1200px 800px at 80% -10%, rgba(124,155,255,.20), transparent 60%),<br>                  radial-gradient(900px 700px at -10% 110%, rgba(70,224,179,.12), transparent 60%),<br>                  var(--bg);<br>      color:var(--text);<br>      line-height:1.55;<br>    }<br><br>    .wrap{<br>      max-width: 980px;<br>      margin: clamp(16px, 4vw, 48px) auto;<br>      padding: 0 16px 48px;<br>    }<br><br>    header{<br>      display:flex;align-items:center;justify-content:space-between;<br>      gap:16px;margin-bottom:18px;<br>    }<br>    .brand{<br>      display:flex;align-items:center;gap:14px;<br>    }<br>    .logo{<br>      width:42px;height:42px;border-radius:12px;<br>      background:<br>        radial-gradient(18px 18px at 30% 30%, #9ad9ff, transparent 70%),<br>        radial-gradient(22px 22px at 70% 70%, #7cffc8, transparent 70%),<br>        linear-gradient(135deg, #5C7CFF 0%, #46E0B3 100%);<br>      box-shadow: var(--shadow);<br>    }<br>    h1{<br>      font-size: clamp(20px, 2.2vw, 28px);<br>      margin:0;<br>    }<br>    .sub{<br>      color:var(--muted);font-size:.95rem;margin-top:4px;<br>    }<br><br>    .toggle{<br>      border:1px solid var(--border);<br>      background:var(--panel);<br>      color:var(--text);<br>      border-radius:12px;padding:10px 14px;cursor:pointer;<br>      box-shadow: var(--shadow);<br>    }<br>    .toggle:hover{opacity:.9}<br><br>    .card{<br>      background: var(--panel);<br>      border:1px solid var(--border);<br>      border-radius: 18px;<br>      box-shadow: var(--shadow);<br>      overflow: clip;<br>    }<br><br>    .section{<br>      padding:20px 20px 16px 20px;<br>      border-bottom:1px solid var(--border);<br>    }<br>    .section:last-child{border-bottom:none}<br><br>    textarea{<br>      width:100%; min-height:130px; resize:vertical;<br>      background: transparent; color: var(--text);<br>      border:1px solid var(--border);<br>      border-radius:14px; padding:14px 14px 40px 14px;<br>      outline: none;<br>    }<br>    textarea:focus{border-color:var(--brand); box-shadow:0 0 0 3px rgba(124,155,255,.25)}<br><br>    .row{display:flex;gap:12px;align-items:center;justify-content:space-between;margin-top:10px}<br><br>    .muted{color:var(--muted)}<br>    .count{font-size:.9rem}<br><br>    .btn{<br>      appearance:none; border:none; cursor:pointer;<br>      background: linear-gradient(135deg, var(--brand), var(--accent));<br>      color:#00111b; font-weight:700;<br>      padding:12px 18px;border-radius:12px;min-width:128px;<br>      box-shadow: 0 10px 20px rgba(76,109,255,.22);<br>      transition: transform .05s ease, box-shadow .15s ease, opacity .15s ease;<br>    }<br>    .btn:hover{transform: translateY(-1px)}<br>    .btn:disabled{opacity:.6; cursor:not-allowed; transform:none}<br><br>    .chips{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px}<br>    .chip{<br>      background:var(--chip); color:var(--text); border:1px solid var(--border);<br>      padding:6px 10px;border-radius:999px; font-size:.9rem<br>    }<br><br>    .result-grid{<br>      display:grid; gap:16px;<br>      grid-template-columns: repeat(12, 1fr);<br>    }<br>    .col-4{grid-column: span 4}<br>    .col-8{grid-column: span 8}<br>    @media (max-width: 880px){<br>      .col-4,.col-8{grid-column: 1 / -1}<br>    }<br><br>    .panel{<br>      border:1px solid var(--border);<br>      background: linear-gradient(180deg, rgba(124,155,255,.06), transparent 60%), var(--panel);<br>      border-radius:14px; padding:14px 14px 10px;<br>      height:100%;<br>    }<br>    .panel h3{margin:0 0 8px 0; font-size:1.02rem}<br><br>    .sentiment-badge{<br>      display:inline-flex;align-items:center;gap:10px;<br>      border-radius:999px; padding:8px 12px; font-weight:700;<br>      color:#00111b; background:#dbe4ff; border:1px solid var(--border)<br>    }<br>    .sentiment-badge[data-kind=&quot;Positive&quot;]{background:#c9f7e8}<br>    .sentiment-badge[data-kind=&quot;Negative&quot;]{background:#ffd6d6}<br>    .sentiment-badge[data-kind=&quot;Neutral&quot;] {background:#e9eefc}<br>    .sentiment-badge[data-kind=&quot;Mixed&quot;]   {background:#ffeec7}<br><br>    .bars{display:grid;gap:8px;margin-top:12px}<br>    .bar{display:grid;grid-template-columns:110px 1fr;align-items:center;gap:10px}<br>    .track{height:10px;border-radius:999px;background:rgba(124,155,255,.18);overflow:hidden;border:1px solid var(--border)}<br>    .fill{height:100%;background:linear-gradient(90deg, var(--brand), var(--accent))}<br><br>    table{<br>      width:100%; border-collapse:collapse; font-size:.95rem; margin-top:6px<br>    }<br>    th,td{border-bottom:1px solid var(--border); padding:10px 8px; text-align:left}<br>    th{color:var(--muted); font-weight:600}<br>    tr:last-child td{border-bottom:none}<br><br>    .toast{<br>      position:fixed; inset:auto 16px 16px auto; z-index:9999;<br>      background:var(--panel); border:1px solid var(--border);<br>      color:var(--text); padding:12px 14px; border-radius:12px; box-shadow:var(--shadow); display:none;<br>    }<br>    .toast.show{display:block; animation:pop .18s ease}<br>    @keyframes pop{from{transform:translateY(6px);opacity:.0}to{transform:none;opacity:1}}<br>    footer{color:var(--muted); font-size:.9rem; margin-top:16px}<br>    a{color:var(--brand);text-decoration:none}<br>  &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body class=&quot;light&quot;&gt;<br>  &lt;div class=&quot;wrap&quot;&gt;<br>    &lt;header&gt;<br>      &lt;div class=&quot;brand&quot;&gt;<br>        &lt;div class=&quot;logo&quot; aria-hidden=&quot;true&quot;&gt;&lt;/div&gt;<br>        &lt;div&gt;<br>          &lt;h1&gt;Smart Sentiment &amp; Content Analyzer&lt;/h1&gt;<br>          &lt;div class=&quot;sub&quot;&gt;Paste any short text—get sentiment, key phrases, and named entities in seconds.&lt;/div&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>      &lt;button class=&quot;toggle&quot; id=&quot;themeBtn&quot; aria-label=&quot;Toggle theme&quot;&gt;🌙 Dark / Light&lt;/button&gt;<br>    &lt;/header&gt;<br><br>    &lt;div class=&quot;card&quot;&gt;<br>      &lt;div class=&quot;section&quot;&gt;<br>        &lt;label for=&quot;inputText&quot; class=&quot;muted&quot;&gt;Your text&lt;/label&gt;<br>        &lt;div style=&quot;position:relative;margin-top:6px&quot;&gt;<br>          &lt;textarea id=&quot;inputText&quot; placeholder=&quot;e.g., I absolutely love the camera but the battery life is disappointing.&quot;&gt;&lt;/textarea&gt;<br>          &lt;div class=&quot;row&quot;&gt;<br>            &lt;div class=&quot;muted count&quot; id=&quot;charCount&quot;&gt;0 characters&lt;/div&gt;<br>            &lt;div style=&quot;display:flex; gap:10px; align-items:center&quot;&gt;<br>              &lt;button class=&quot;btn&quot; id=&quot;analyzeBtn&quot;&gt;Analyze&lt;/button&gt;<br>            &lt;/div&gt;<br>          &lt;/div&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br><br>      &lt;div class=&quot;section&quot; id=&quot;resultsSection&quot; style=&quot;display:none&quot;&gt;<br>        &lt;div class=&quot;result-grid&quot;&gt;<br>          &lt;div class=&quot;col-4&quot;&gt;<br>            &lt;div class=&quot;panel&quot;&gt;<br>              &lt;h3&gt;Overall sentiment&lt;/h3&gt;<br>              &lt;div id=&quot;sentimentBadge&quot; class=&quot;sentiment-badge&quot; data-kind=&quot;Neutral&quot;&gt;Neutral&lt;/div&gt;<br>              &lt;div class=&quot;bars&quot;&gt;<br>                &lt;div class=&quot;bar&quot;&gt;<br>                  &lt;div class=&quot;muted&quot;&gt;Positive&lt;/div&gt;<br>                  &lt;div class=&quot;track&quot;&gt;&lt;div class=&quot;fill&quot; id=&quot;pPos&quot; style=&quot;width:0%&quot;&gt;&lt;/div&gt;&lt;/div&gt;<br>                &lt;/div&gt;<br>                &lt;div class=&quot;bar&quot;&gt;<br>                  &lt;div class=&quot;muted&quot;&gt;Negative&lt;/div&gt;<br>                  &lt;div class=&quot;track&quot;&gt;&lt;div class=&quot;fill&quot; id=&quot;pNeg&quot; style=&quot;width:0%&quot;&gt;&lt;/div&gt;&lt;/div&gt;<br>                &lt;/div&gt;<br>                &lt;div class=&quot;bar&quot;&gt;<br>                  &lt;div class=&quot;muted&quot;&gt;Neutral&lt;/div&gt;<br>                  &lt;div class=&quot;track&quot;&gt;&lt;div class=&quot;fill&quot; id=&quot;pNeu&quot; style=&quot;width:0%&quot;&gt;&lt;/div&gt;&lt;/div&gt;<br>                &lt;/div&gt;<br>                &lt;div class=&quot;bar&quot;&gt;<br>                  &lt;div class=&quot;muted&quot;&gt;Mixed&lt;/div&gt;<br>                  &lt;div class=&quot;track&quot;&gt;&lt;div class=&quot;fill&quot; id=&quot;pMix&quot; style=&quot;width:0%&quot;&gt;&lt;/div&gt;&lt;/div&gt;<br>                &lt;/div&gt;<br>              &lt;/div&gt;<br>            &lt;/div&gt;<br>          &lt;/div&gt;<br><br>          &lt;div class=&quot;col-8&quot;&gt;<br>            &lt;div class=&quot;panel&quot;&gt;<br>              &lt;h3&gt;Key phrases&lt;/h3&gt;<br>              &lt;div id=&quot;phrases&quot; class=&quot;chips&quot;&gt;&lt;/div&gt;<br>              &lt;h3 style=&quot;margin-top:14px&quot;&gt;Entities&lt;/h3&gt;<br>              &lt;table id=&quot;entitiesTbl&quot;&gt;<br>                &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Text&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;<br>                &lt;tbody&gt;&lt;/tbody&gt;<br>              &lt;/table&gt;<br>            &lt;/div&gt;<br>          &lt;/div&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br><br>    &lt;/div&gt;<br><br>    &lt;footer&gt;<br>      Tip: press &lt;b&gt;Ctrl / Cmd + Enter&lt;/b&gt; to analyze quickly. &amp;nbsp;•&amp;nbsp;<br>      &lt;a href=&quot;#&quot; id=&quot;sample&quot;&gt;Try a sample&lt;/a&gt;<br>    &lt;/footer&gt;<br>  &lt;/div&gt;<br><br>  &lt;div class=&quot;toast&quot; id=&quot;toast&quot;&gt;&lt;/div&gt;<br><br>  &lt;script&gt;<br>    // 🔧 Replace with your Invoke URL if it changes later.<br>    const API_URL = &#39;https://l36mrksep9.execute-api.eu-north-1.amazonaws.com/prod/analyze&#39;;<br><br>    const input = document.getElementById(&#39;inputText&#39;);<br>    const btn = document.getElementById(&#39;analyzeBtn&#39;);<br>    const badge = document.getElementById(&#39;sentimentBadge&#39;);<br>    const phrasesWrap = document.getElementById(&#39;phrases&#39;);<br>    const entitiesTbl = document.querySelector(&#39;#entitiesTbl tbody&#39;);<br>    const section = document.getElementById(&#39;resultsSection&#39;);<br>    const charCount = document.getElementById(&#39;charCount&#39;);<br>    const toast = document.getElementById(&#39;toast&#39;);<br>    const themeBtn = document.getElementById(&#39;themeBtn&#39;);<br>    const sample = document.getElementById(&#39;sample&#39;);<br><br>    function showToast(msg){ toast.textContent = msg; toast.classList.add(&#39;show&#39;); setTimeout(()=&gt;toast.classList.remove(&#39;show&#39;), 2800); }<br><br>    function fmtPct(x){ return (x*100).toFixed(1)+&#39;%&#39;; }<br>    function setBar(id, val){ document.getElementById(id).style.width = Math.min(100, Math.max(0, val*100)) + &#39;%&#39;; }<br><br>    function setBadge(kind){<br>      badge.setAttribute(&#39;data-kind&#39;, kind);<br>      badge.textContent = kind;<br>    }<br><br>    function render(result){<br>      // sentiment + scores<br>      setBadge(result.sentiment);<br>      const s = result.sentimentScores || {};<br>      setBar(&#39;pPos&#39;, s.Positive || 0);<br>      setBar(&#39;pNeg&#39;, s.Negative || 0);<br>      setBar(&#39;pNeu&#39;, s.Neutral || 0);<br>      setBar(&#39;pMix&#39;, s.Mixed || 0);<br><br>      // key phrases<br>      phrasesWrap.innerHTML = &#39;&#39;;<br>      (result.keyPhrases || []).slice(0, 30).forEach(t=&gt;{<br>        const span = document.createElement(&#39;span&#39;);<br>        span.className = &#39;chip&#39;;<br>        span.textContent = t;<br>        phrasesWrap.appendChild(span);<br>      });<br><br>      // entities<br>      entitiesTbl.innerHTML = &#39;&#39;;<br>      (result.entities || []).slice(0, 80).forEach(e=&gt;{<br>        const tr = document.createElement(&#39;tr&#39;);<br>        const td1 = document.createElement(&#39;td&#39;); td1.textContent = e.Text;<br>        const td2 = document.createElement(&#39;td&#39;); td2.textContent = e.Type;<br>        tr.append(td1, td2); entitiesTbl.appendChild(tr);<br>      });<br><br>      section.style.display = &#39;block&#39;;<br>    }<br><br>    async function analyze(){<br>      const text = (input.value || &#39;&#39;).trim();<br>      if(!text){ showToast(&#39;Please enter some text.&#39;); input.focus(); return; }<br><br>      btn.disabled = true; const original = btn.textContent; btn.textContent = &#39;Analyzing…&#39;;<br><br>      try{<br>        const res = await fetch(API_URL, {<br>          method: &#39;POST&#39;,<br>          headers: { &#39;Content-Type&#39;: &#39;application/json&#39; },<br>          body: JSON.stringify({ text })<br>        });<br><br>        const json = await res.json().catch(()=&gt;({}));<br>        if(!res.ok){<br>          console.error(&#39;API error&#39;, res.status, json);<br>          showToast(&#39;API error: &#39; + (json.error || res.status));<br>        }else{<br>          render(json);<br>        }<br>      }catch(err){<br>        console.error(err);<br>        showToast(&#39;Network error. Check the API URL &amp; CORS.&#39;);<br>      }finally{<br>        btn.disabled = false; btn.textContent = original;<br>      }<br>    }<br><br>    // events<br>    btn.addEventListener(&#39;click&#39;, analyze);<br>    input.addEventListener(&#39;input&#39;, ()=&gt;{ charCount.textContent = `${input.value.length} characters`; });<br>    input.addEventListener(&#39;keydown&#39;, (e)=&gt;{ if((e.metaKey || e.ctrlKey) &amp;&amp; e.key===&#39;Enter&#39;){ analyze(); }});<br>    themeBtn.addEventListener(&#39;click&#39;, ()=&gt;{ document.body.classList.toggle(&#39;light&#39;); });<br>    sample.addEventListener(&#39;click&#39;, (e)=&gt;{<br>      e.preventDefault();<br>      input.value = &quot;I absolutely love the new phone’s camera. The screen is gorgeous, but the battery life is disappointing and the price feels high.&quot;;<br>      input.dispatchEvent(new Event(&#39;input&#39;));<br>    });<br><br>    // init<br>    charCount.textContent = &#39;0 characters&#39;;<br>  &lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>lambda_function.py</p><pre>import json<br>import os<br>import boto3<br>import traceback<br><br>REGION = os.getenv(&quot;COMPREHEND_REGION&quot;, &quot;eu-west-1&quot;)<br>comprehend = boto3.client(&quot;comprehend&quot;, region_name=REGION)<br><br>CORS_ORIGIN = os.getenv(&quot;CORS_ORIGIN&quot;, &quot;*&quot;)<br><br>def _resp(status, body):<br>    return {<br>        &quot;statusCode&quot;: status,<br>        &quot;headers&quot;: {<br>            &quot;Access-Control-Allow-Origin&quot;: CORS_ORIGIN,<br>            &quot;Access-Control-Allow-Headers&quot;: &quot;Content-Type&quot;,<br>            &quot;Access-Control-Allow-Methods&quot;: &quot;OPTIONS,POST&quot;,<br>            &quot;Content-Type&quot;: &quot;application/json&quot;<br>        },<br>        &quot;body&quot;: json.dumps(body)<br>    }<br><br>def lambda_handler(event, context):<br>    if event.get(&quot;httpMethod&quot;) == &quot;OPTIONS&quot;:<br>        return _resp(200, {&quot;ok&quot;: True})<br>    try:<br>        body = {}<br>        if &quot;body&quot; in event and event[&quot;body&quot;]:<br>            body = json.loads(event[&quot;body&quot;])<br>        text = (body.get(&quot;text&quot;) or &quot;&quot;).strip()<br>        if not text:<br>            return _resp(400, {&quot;error&quot;: &quot;Missing &#39;text&#39; in body&quot;})<br><br>        s = comprehend.detect_sentiment(Text=text, LanguageCode=&quot;en&quot;)<br>        kp = comprehend.detect_key_phrases(Text=text, LanguageCode=&quot;en&quot;)<br>        ent = comprehend.detect_entities(Text=text, LanguageCode=&quot;en&quot;)<br><br>        result = {<br>            &quot;sentiment&quot;: s[&quot;Sentiment&quot;],<br>            &quot;sentimentScores&quot;: s[&quot;SentimentScore&quot;],<br>            &quot;keyPhrases&quot;: [p[&quot;Text&quot;] for p in kp.get(&quot;KeyPhrases&quot;, [])],<br>            &quot;entities&quot;: [{&quot;Text&quot;: e[&quot;Text&quot;], &quot;Type&quot;: e[&quot;Type&quot;]} for e in ent.get(&quot;Entities&quot;, [])]<br>        }<br>        return _resp(200, result)<br>    except Exception as e:<br>        print(&quot;Error:&quot;, e)<br>        print(traceback.format_exc())  # full stack in CloudWatch<br>        return _resp(500, {&quot;error&quot;: &quot;Internal error&quot;})</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0a3bc5edd280" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>