惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
T
Tailwind CSS Blog
罗磊的独立博客
B
Blog
博客园_首页
A
About on SuperTechFans
有赞技术团队
有赞技术团队
V
V2EX
U
Unit 42
I
InfoQ
IT之家
IT之家
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
The Cloudflare Blog
H
Help Net Security

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Building Last Message: A Local-First Gemma Emergency Inte...
Harish Kotra · 2026-05-19 · via DEV Community

Last Message is a Streamlit app designed for high-stress disaster communication. The problem is simple: during emergencies, people panic and communication quality collapses. The goal was to convert chaotic speech and text into structured, actionable rescue intelligence with Gemma.

This post explains the architecture, model routing, multimodal analysis, stress-adaptive prompting, and UX choices that made the app practical for hackathon judging and real-world constraints.

1) Design constraints

We intentionally stayed lightweight:

  • no database
  • no auth
  • no orchestration framework
  • no vector store
  • no additional backend

Everything runs in a single Streamlit app with modular Python utilities and embedded browser components.

2) System architecture

System architecture

3) Local-first model routing with fallback

Emergency resilience requires operation under degraded network conditions. The app routes inference based on environment availability:

  • local Gemma first (LM Studio)
  • cloud fallback (OpenRouter)
  • optional simulated network failure mode to force local path
def run_text_inference(system_prompt: str, user_prompt: str, cfg: ModelConfig) -> str:
    primary, cloud_available = provider_state(cfg)
    if primary is None:
        raise InferenceError("No model provider configured in .env")

    try:
        if primary == "local":
            return run_lm_studio_inference(system_prompt, user_prompt, cfg)
        return run_openrouter_inference(system_prompt, user_prompt, cfg)
    except InferenceError:
        if primary == "local" and cloud_available and not st.session_state.network_failure_mode:
            return run_openrouter_inference(system_prompt, user_prompt, cfg)
        raise

Enter fullscreen mode Exit fullscreen mode

4) Stress-adaptive prompting

The app estimates panic severity from transcript signals and adapts model instruction style:

  • high panic -> short, calmer steps
  • moderate panic -> concise complete guidance
  • high clarity -> slightly more detail
state = emotional_state(st.session_state.panic_input)
style_line = (
    "Use very short step-by-step instructions and calming language."
    if state["response_style"] == "short"
    else "Use concise but complete instructions with calm tone."
)
system_prompt = load_emergency_system_prompt() + "\nAdaptive response mode: " + style_line

Enter fullscreen mode Exit fullscreen mode

This is not a new model capability; it is a response-policy layer optimized for cognitive load.

5) Multimodal scene analysis

We added image understanding for disaster scenes using OpenAI-compatible multimodal payloads for both local/cloud providers.

payload = {
    "model": model_config.lm_studio_model,
    "messages": [
        {"role": "system", "content": system_prompt},
        {
            "role": "user",
            "content": [
                {"type": "text", "text": user_text},
                {"type": "image_url", "image_url": {"url": image_data_url}},
            ],
        },
    ],
}

Enter fullscreen mode Exit fullscreen mode

Output is normalized into tactical fields:

  • visible hazards
  • structural risks
  • injury indicators
  • escape recommendations
  • safety warnings
  • rescue priority

6) Multi-agent consensus without frameworks

Instead of introducing heavyweight agents, we used role-separated prompt variants:

  • Medic Agent
  • Structural Agent
  • Rescue Coordinator Agent

Then we synthesize a final command-level decision. This gives coordinated reasoning while keeping runtime simple.

7) Responder HUD and cognitive readability

A key learning: technically correct output is useless if unreadable in panic.

We refactored rendering to “emergency chunks”:

  • severity chip
  • 1-line summary
  • 2–3 action bullets

No long paragraphs. No dense blocks.

Responder View moved from paragraph report to HUD-like metric tiles:

  • victims
  • extraction priority
  • structural risk
  • injury severity
  • equipment
  • rescue difficulty

8) Browser voice capture reliability

Web Speech API behavior differs across browsers. We handled instability with:

  • explicit recorder state machine
  • transient error retries
  • forced transcript commit on stop
  • manual fallback dictation input if browser path fails

This improved demo reliability significantly.

9) Geo context

The app requests browser geolocation permission by default and attempts reverse geocoding to auto-fill:

  • latitude
  • longitude
  • city
  • nearby landmark

This removes hardcoded location assumptions and improves responder usefulness.

10) Developer workflow

The project remains easy to fork:

git clone https://github.com/harishkotra/last-message.git
cd last-message
cp .env.example .env
pip install -r requirements.txt
streamlit run app.py

Enter fullscreen mode Exit fullscreen mode

11) What we would build next

  • on-device text-to-speech for emergency steps
  • map pins + safe route overlays
  • incident timeline snapshots for responders
  • red-team prompt hardening for false certainty control
  • multilingual quality tuning per region

12) Final take

Last Message demonstrates a practical principle for AI in disasters:

The best emergency AI is not the one that talks the most. It is the one that reduces chaos into clear next actions.

When words fail, AI helps humans be heard.

Code and more: https://www.dailybuild.xyz/project/137-last-message