跳到正文
DEV Community· Arpita Rout·· 4 小時前AI 評分35

Sloth Companion:由 Gemma 2 驅動的離線睡前故事與音景生成器

Sloth Companion: An Offline Bedtime Story & Soundscape Generator Powered by Gemma 2

AI 導讀

Sloth Companion 是一款以 Gemma 2(gemma2:2b)和 Ollama 建構的離線睡前故事及音景生成器。用戶輸入兩個主題後,程式會在本機生成一篇 3 段故事及一份列出 3 種背景聲音的音景配方,無須連接互聯網或使用雲端 API。

正文

Arpita Rout

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 3: Slow and Steady

What I Built

Sloth Companion is a local, privacy-focused bedtime story and soundscape generator designed to help you unplug and wind down at the end of the day.

Instead of mindlessly scrolling through feeds or exposing your personal habits to cloud APIs, Sloth Companion takes two simple cozy themes (e.g., "Rain on a tin roof" and "Warm tea") and generates a soothing 3-paragraph bedtime story alongside an ambient soundscape recipe—100% offline on your own machine.

Demo

A screenshot of the Sloth Mode: Offline Wind-Down Companion app running in a web browser with a dark theme. It shows two text input fields:

A screenshot showing the same Sloth Mode app but with a light background theme. The text inputs are visible at the top. Below the inputs, the response has loaded, displaying a clean

A clean screenshot of the complete Sloth Mode app interface in light mode. This image shows the header (

Code

🌙 Sloth Companion: Offline Wind-Down Companion

An offline, privacy-focused bedtime story and ambient soundscape generator powered by Gemma 2 (gemma2:2b) via Ollama and built with Streamlit.

🦥 Overview

Sloth Companion helps you unplug and relax at the end of the day. By entering two cozy themes (e.g., "Rain on a tin roof" and "Warm tea"), the application generates a calming 3-paragraph bedtime story alongside a custom ambient soundscape recipe—100% locally on your machine.


✨ Features

  • 100% Offline & Private: Runs entirely on local hardware using Ollama. No data leaves your machine, no cloud API calls, and works in Airplane Mode.
  • Lightweight LLM: Uses Google's open-weight gemma2:2b model for quick, local story generation.
  • Simple UI: Minimalist Streamlit interface built for evening wind-down routines.

🛠️ Prerequisites & Setup

Install Ollama
Download and install Ollama, then pull the Gemma 2 model in your terminal:

ollama run

…

import streamlit as st
import ollama

st.set_page_config(
    page_title="Offline Wind-Down Companion",
    page_icon=":moon:",
    layout="centered"
)

st.title(":moon: Sloth Mode: Offline Wind-Down Companion")
st.caption("100% Local :sparkles: Zero Internet Required :sparkles: Powered by Gemma 2")

st.write(
    "Disconnect from the noise. Enter two soothing themes below "
    "to generate a local, calming bedtime story and ambient audio recipe."
)

col1, col2 = st.columns(2)
with col1:
    word1 = st.text_input("First Cozy Theme:", value="Rain on a tin roof")
with col2:
    word2 = st.text_input("Second Cozy Theme:", value="Warm tea")

if st.button("Generate Wind-Down Story :sparkles:", use_container_width=True):
    if not word1.strip() or not word2.strip():
        st.warning("Please enter two themes to guide your story.")
    else:
        with st.spinner("Crafting your story completely offline..."):
            prompt = f"""
            You are a gentle and soothing bedtime storyteller. 
            Write a very short, ultra-relaxing 3-paragraph bedtime story incorporating these two themes: '{word1}' and '{word2}'. 
            Use slow, atmospheric, and calming imagery.
            At the end, provide a section titled 'Ambient Soundscape Recipe' that lists 3 cozy background sounds to play along with this story.
            """

            try:
                response = ollama.chat(
                    model='gemma2:2b',
                    messages=[{'role': 'user', 'content': prompt}]
                )

                st.markdown("---")
                st.markdown("### Your Bedtime Story")
                st.write(response['message']['content'])
                st.success("Generated 100% locally on your machine.")

            except Exception as e:
                st.error(f"Could not connect to Ollama. Make sure Ollama is running: {e}")

How I Built It

Language & UI: Python + Streamlit for a fast, clean local web dashboard.

LLM Engine: Ollama running Google's lightweight Gemma 2 (gemma2:2b) model locally.

Zero External Dependencies: Built entirely with local inference so no API keys, cloud tokens, or active internet connections are required.

Why Does Open Innovation Matter?

Open-weight models like *Gemma 2 * fundamentally change how personal AI applications can be built:

  1. Complete Privacy: bedtime prompts, personal sleep routines, and daily thoughts never leave your local hardware.

    1. True Offline Functionality: Works in Airplane Mode, during network outages, or on a cabin retreat deep in the woods.
    2. Zero Operating Costs: No per-token API charges or subscription fees—it runs completely free forever once downloaded

The Lazy Payoff

In line with the "Slow and Steady" theme, Sloth Companion saves effort by eliminating the search fatigue of finding bedtime reading material or relaxation guides. With just two clicks, you get a uniquely tailored, soothing routine that lets you disconnect from the web completely.

Prize Categories

Best Use of Gemma (powered locally by Google's open-weight gemma2:2b model via Ollama)

來源:DEV Community · dev.to