<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akifin</title>
    <description>The latest articles on DEV Community by Akifin (@akifin_6f85bfd38e12738869).</description>
    <link>https://dev.to/akifin_6f85bfd38e12738869</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3491486%2F060f5abb-8449-49b2-b29c-c41a8d1d4777.jpg</url>
      <title>DEV Community: Akifin</title>
      <link>https://dev.to/akifin_6f85bfd38e12738869</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akifin_6f85bfd38e12738869"/>
    <language>en</language>
    <item>
      <title>Inside Quantum Ball: Building a Playful Oracle with AI Studio + Cloud Run</title>
      <dc:creator>Akifin</dc:creator>
      <pubDate>Tue, 11 Nov 2025 00:56:56 +0000</pubDate>
      <link>https://dev.to/akifin_6f85bfd38e12738869/inside-quantum-ball-building-a-playful-oracle-with-ai-studio-cloud-run-5g9l</link>
      <guid>https://dev.to/akifin_6f85bfd38e12738869/inside-quantum-ball-building-a-playful-oracle-with-ai-studio-cloud-run-5g9l</guid>
      <description>&lt;p&gt;Quantum Ball is a voice-powered manifestation oracle that fuses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;your spoken question&lt;/li&gt;
&lt;li&gt;a hashed “voice signature”&lt;/li&gt;
&lt;li&gt;true quantum randomness&lt;/li&gt;
&lt;li&gt;and Gemini 2.5 Flash&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;…into a single, short, on-brand answer that leans hopeful—but can still say “unclear” or even “no” when that feels honest.&lt;/p&gt;

&lt;p&gt;Built for the &lt;strong&gt;Google Cloud Run Hackathon (AI Studio Category)&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Try it / Code
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Live demo&lt;/strong&gt;&lt;br&gt;
👉 &lt;a href="https://gen-lang-client-0524129649.web.app" rel="noopener noreferrer"&gt;https://gen-lang-client-0524129649.web.app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;YouTube demo&lt;/strong&gt;&lt;br&gt;
👉 &lt;a href="https://youtu.be/yDDZvLX93AE?si=H2q6BpWb7YAFCQhG" rel="noopener noreferrer"&gt;https://youtu.be/yDDZvLX93AE?si=H2q6BpWb7YAFCQhG&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The demo may be rate-limited at times; please see the repo README for details.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Source code&lt;/strong&gt;&lt;br&gt;
👉 &lt;a href="https://github.com/memetcircus/Quantum_Ball" rel="noopener noreferrer"&gt;https://github.com/memetcircus/Quantum_Ball&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  The core idea
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Most people don’t run out of options.&lt;/p&gt;

&lt;p&gt;They run out of belief.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Quantum Ball is designed as a tiny cinematic ritual:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; You speak a personal, future-facing question.&lt;/li&gt;
&lt;li&gt; The system checks: is this safe, relevant, and in-scope?&lt;/li&gt;
&lt;li&gt; If yes, it entangles your voice hash with quantum randomness.&lt;/li&gt;
&lt;li&gt; Gemini turns that into a constrained, in-character answer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Not fortune-telling. Not toxic positivity.&lt;/p&gt;

&lt;p&gt;A gentle nudge back toward “good things can happen — to me — from here”.&lt;/p&gt;




&lt;h3&gt;
  
  
  High-level architecture
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Frontend
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Static, responsive web app on &lt;strong&gt;Firebase Hosting&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;HTML + CSS + vanilla JS&lt;/li&gt;
&lt;li&gt;Voice capture via &lt;code&gt;MediaRecorder&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Canvas-based “Quantum Grid” background&lt;/li&gt;
&lt;li&gt;Sends &lt;code&gt;audio.bin&lt;/code&gt; via &lt;code&gt;multipart/form-data&lt;/code&gt; → &lt;code&gt;/ask&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Backend
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Python + Flask on &lt;strong&gt;Google Cloud Run&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;CORS locked to Firebase origins&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flask-Limiter:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;global: 200/day, 50/hour&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/ask&lt;/code&gt;: 10/min per IP&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Uses:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Google Cloud Speech-to-Text (&lt;code&gt;WEBM_OPUS&lt;/code&gt; → &lt;code&gt;LINEAR16&lt;/code&gt; fallback)&lt;/li&gt;
&lt;li&gt;Gemini 2.5 Flash via &lt;code&gt;google-genai&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;ANU QRNG API for true randomness&lt;/li&gt;
&lt;li&gt;Pydantic for strict JSON schemas&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  Designed first in Google AI Studio
&lt;/h3&gt;

&lt;p&gt;We built two dedicated prompt “components” in Google AI Studio, then embedded them into &lt;code&gt;main.py&lt;/code&gt;:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. The Classifier
&lt;/h4&gt;

&lt;p&gt;Gemini 2.5 Flash prompt with structured output:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;relevant&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;irrelevant_statement&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;harmful_query&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;inappropriate_query&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;plus &lt;code&gt;relevance_score&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Used as the primary gate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Harmful&lt;/strong&gt; → static crisis-style support message&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inappropriate&lt;/strong&gt; → short, firm mystical refusal&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Irrelevant / command&lt;/strong&gt; → charismatic nudge to ask a real question&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Relevant&lt;/strong&gt; → allowed into the quantum path&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. The Creative Generator
&lt;/h4&gt;

&lt;p&gt;A second Gemini 2.5 Flash prompt:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Input:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;USER_QUESTION&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;JUDGMENT_TYPE&lt;/code&gt; (Positive / Non-committal / Negative)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;INSPIRATION_PHRASE&lt;/code&gt; (one of 20 classic-style outcomes)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Output (JSON):&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;creative_answer&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;judgment_type&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;This keeps answers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;short&lt;/li&gt;
&lt;li&gt;poetic&lt;/li&gt;
&lt;li&gt;consistently “Quantum Ball” in voice&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Quantum randomness + voice entanglement
&lt;/h3&gt;

&lt;p&gt;For relevant queries:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quantum cache&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetches batches of &lt;code&gt;uint8&lt;/code&gt; values from ANU QRNG.&lt;/li&gt;
&lt;li&gt;Thread-safe cache (lock + FIFO).&lt;/li&gt;
&lt;li&gt;Respects rate limits; falls back to pseudo-random only if empty.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Voice hash&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;SHA-256&lt;/code&gt; of raw audio → &lt;code&gt;voice_signature_bytes&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Never stored as identity; used purely as entropy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Entanglement&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Take one quantum byte.&lt;/li&gt;
&lt;li&gt; XOR with all bytes of &lt;code&gt;voice_signature_bytes&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt; Map result into &lt;code&gt;[0..19]&lt;/code&gt; → 20 Magic 8-Ball–style outcomes:

&lt;ul&gt;
&lt;li&gt;10 Positive&lt;/li&gt;
&lt;li&gt;5 Non-committal&lt;/li&gt;
&lt;li&gt;5 Negative&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Gemini final pass&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Creative Generator rewrites that chosen outcome into a custom line.&lt;/li&gt;
&lt;li&gt;Frontend renders it inside the Quantum Ball with adaptive typography.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Net effect: answers feel personal, repeatable per ritual, and more than just “LLM says stuff”.&lt;/p&gt;




&lt;h3&gt;
  
  
  Safety &amp;amp; reliability
&lt;/h3&gt;

&lt;p&gt;Key decisions:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layered safety&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Command prefix filter (e.g. “tell me…”, meta prompts).&lt;/li&gt;
&lt;li&gt;AI Studio–tuned 4-way classifier.&lt;/li&gt;
&lt;li&gt;Hardcoded self-harm support message.&lt;/li&gt;
&lt;li&gt;Strict mystical refusals for harassment/violence.&lt;/li&gt;
&lt;li&gt;Gemini safety as an extra guardrail.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Production-ish hygiene&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rate limiting on &lt;code&gt;/ask&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;CORS locked to official frontend&lt;/li&gt;
&lt;li&gt;Clear JSON errors (no speech detected, etc.)&lt;/li&gt;
&lt;li&gt;No secrets in repo (env vars only)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This lets us keep the experience playful and responsible.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why this stack works
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AI Studio&lt;/strong&gt; → design prompts like real backend components, with structured output.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Run&lt;/strong&gt; → one clean container for the oracle brain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Firebase Hosting&lt;/strong&gt; → fast, global frontend.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gemini + STT + QRNG&lt;/strong&gt; → modern Magic 8-Ball with real entropy &amp;amp; personality.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Submitted for the Google Cloud Run Hackathon – AI Studio Category&lt;/p&gt;

&lt;h1&gt;
  
  
  CloudRunHackathon #GoogleCloud #AIStudio #Gemini #CloudRun #Firebase #QRNG
&lt;/h1&gt;

</description>
      <category>cloudrunhackathon</category>
    </item>
  </channel>
</rss>
