Sarvam AI Cookbook

repository·main·Indexed 41 days ago

https://github.com/sarvamai/sarvam-ai-cookbook

A collection of tutorials and examples for Sarvam AI's speech and language models. Includes implementations for Batch Speech-to-Text (STT), the AI Presentation Architect, AI Graph Generator, Birthday Song Generator using sarvam-105b, Government Scheme Summarizer using mayura:v1, Indic Soundbox AI using saaras:v3 and bulbul:v3, and live video transcription.

Tokens
44.3K
Snippets
135
Records
192
Agent score
51%

What's inside Sarvam AI Cookbook

  1. Overview of the Birthday Song Generator project

    main
    The Birthday Song Generator is a demonstration project that uses SarvamAI's sarvam-105b model to create personalized, 12-line rhyming birthday songs. It takes 10 user inputs (such as name, hobbies, and favorite foods) and processes them through a FastAPI backend to generate a custom song designed for a fun, 'roasting' or heartfelt experience.
  2. Overview of Government Scheme Summarizer

    main

    The Government Scheme Summarizer is a tool designed to help Indian citizens understand government welfare schemes. It takes a scheme name or description and produces a plain-language, bullet-point summary backed by official sources (using wiki grounding). The tool can then translate this summary into any of 10 supported Indian languages.

    Key Features:

    • Summarization: Uses Sarvam's Chat Completions API (sarvam-105b) with wiki grounding.
    • Category Hinting: Supports optional category hints (e.g., "Banking, Financial Services & Insurance (BFSI)") to improve summary accuracy.
    • Translation: Uses Sarvam's Translate API (mayura:v1) to translate summaries into Hindi, Tamil, Telugu, Bengali, Malayalam, Kannada, Marathi, Gujarati, Punjabi, or Odia.
    • Automatic Chunking: Handles long summaries by automatically chunking text to respect the Translate API's per-request character limits.
  3. Overview of AI Presentation Architect

    main
    The AI Presentation Architect is a Streamlit-based web application that automates the creation of multilingual PowerPoint presentations. By providing a single topic, the tool uses Sarvam AI's models to generate slide titles, bullet points, translations, and audio narration. It outputs a downloadable .pptx file containing the generated content and regional language audio.
  4. Key features and behaviors of the Multilingual Chatbot

    main

    The Multilingual Chatbot is designed with the following capabilities:

    • Automatic Language Detection: Detects whether the input is English or a regional language.
    • Context Preservation: Maintains conversation context for the last 5 turns.
    • Translation Fallback: If an API call fails or a query is unsupported, the system uses translation fallback capabilities.
    • Credit Usage: Consumes Sarvam AI credits based on conversation length. New accounts typically receive 1,000 free credits.
  5. How the Live Transcription architecture works

    main

    The system achieves real-time transcription and translation through a streaming pipeline:

    1. Audio Capture: The browser uses the Web Audio API to capture audio from a video, resampling it to 16kHz mono WAV format.
    2. Streaming: The browser sends ~1 second audio frames to the Flask server via Socket.IO.
    3. Server-side Processing: For every client, the Flask server maintains one persistent streaming connection to the Sarvam AI API for each active mode (transcribe or translate).
    4. Result Delivery: As the Sarvam AI API finalizes text segments, the server pushes these transcripts/translations back to the browser over the existing Socket.IO connection.
  6. How Saaras streaming models differ

    main

    Sarvam provides two distinct streaming paths depending on your use case and access level:

    FeatureSaaras v3 (Standard)Saaras v3-realtime (Beta)
    Primary UseBatch & standard streamingUltra-low latency streaming
    Endpointwss://api.sarvam.ai/speech-to-text/wswss://api.sarvam.ai/speech-to-text-realtime/ws
    SDK SupportSupported by sarvamai SDKRequires direct WebSocket connection
    Audio FormatWAV or 16kHz mono PCMRaw PCM only (no WAV headers)
    Mode ApplicationApplied to transcriptsApplied to final transcripts only
  7. How the Indic Soundbox AI workflow works

    main

    The application follows a multi-step pipeline to provide voice-based business insights in local languages:

    1. Audio Capture: The frontend records audio via the microphone.
    2. ASR (Speech-to-Text): Audio is sent to the /asr endpoint, which uses Sarvam ASR (saaras:v3) to generate a transcript.
    3. LID (Language Identification): The transcript is sent to the /lid endpoint to detect the spoken language using Sarvam LID.
    4. LLM (Chat/Reasoning): The transcript and the detected language are sent to the /chat endpoint. The backend prepends context from merchant_context.md to the prompt and calls the Sarvam-105B chat model.
    5. TTS (Text-to-Speech): The LLM's text response and the detected language code are sent to the /tts endpoint. The backend uses Sarvam TTS (bulbul:v3) to generate audio.
    6. Playback: The resulting audio (as a base64 data URI) is returned to the frontend for the user to play.
  8. AI Presentation Architect Features and Integrations

    main

    The application integrates several Sarvam AI APIs and Python libraries to achieve its functionality:

    • Content Generation: Uses Sarvam's Chat API to create slide titles and bullet points.
    • Translation: Uses Sarvam's Translate API to support 8 different Indian languages.
    • Audio Narration: Uses Sarvam's TTS (Text-to-Speech) API to generate regional language audio for each slide.
    • PPTX Generation: Uses the python-pptx library to construct the final presentation file.
    • User Interface: Built with Streamlit for an interactive web experience.
  9. How the podcast generation pipeline works

    main

    The podcast generation is an asynchronous, multi-step process managed by Inngest to ensure reliability. The workflow is as follows:

    1. PDF Parsing: The uploaded document is parsed using Sarvam Document Intelligence (Sarvam Vision) to extract text and metadata.
    2. Script Generation: An intelligent conversational script is created using the Sarvam 105B model.
    3. Text-to-Speech (TTS): The script is converted into high-quality audio using the Sarvam Bulbul v3 TTS API.
    4. Background Processing: Each step is handled as a background job, allowing the user to monitor real-time progress via the job-status API without blocking the UI.

    Note on PDF Size: Very large PDFs may cause generation to fail due to the context length limitations of the Sarvam 105B model. While the system attempts to chunk content, extremely extensive documents should be avoided for optimal performance.

  10. Run the Regional Code Helper application

    main

    The application is built using Streamlit. Once dependencies are installed and the SARVAM_API_KEY is set in a .env file, run the following command to start the web interface:

    streamlit run coding_assistant.py

    After running the command, open your web browser and navigate to the local URL provided in the terminal (typically http://localhost:8501).

  11. Setup the AI Travel Assistant

    main

    To run the AI Travel Assistant locally, clone the repository, install the required Python dependencies, and configure your Sarvam API key. The application is built using Streamlit.

    # 1. Install dependencies
    pip install -r requirements.txt
    
    # 2. Configure environment variable
    # Create a .env file in the root directory with:
    # SARVAM_API_KEY=your_api_key_here
    
    # 3. Run the application
    streamlit run app.py