AIDecember 14, 20243 min read

Introducing SANGAM AI: The Ultimate AI Toolkit for Text, Speech, Image, and Video

SANGAM AI is an all-in-one Python + Streamlit toolkit combining text generation, speech synthesis, image creation, and video processing in a single web app.

Galvan

Galvan

Founder & Creator

Introduction

SANGAM AI is an all-in-one AI toolkit built with Python and Streamlit. It brings together four powerful capabilities — text generation, speech synthesis, image creation, and video processing — in a single, easy-to-use web app. SANGAM combines several models into one app. For a deeper dive into the chat side, see the Mistral AI chatbot tutorial.


> šŸŽ¬ Watch the Full Video Tutorial:

> Learn how to build it step-by-step on YouTube: The 7th Semester Project That Will Make You a SANGAM AI Master


What SANGAM AI Can Do

  • Text Generation — Generate creative content and summaries using Mistral AI.
  • Text-to-Speech — Convert any text into natural audio using gTTS.
  • Image Generation — Create AI images from text prompts.
  • Video Processing — Trim and convert video files directly in the browser.
  • Prerequisites

    Install the required libraries:

    code
    pip install streamlit mistralai gtts Pillow requests

    You will also need a Mistral AI API key from mistral.ai.

    Project Structure

    code
    sangam_ai/
    ā”œā”€ā”€ app.py
    ā”œā”€ā”€ modules/
    │   ā”œā”€ā”€ text_gen.py
    │   ā”œā”€ā”€ tts.py
    │   ā”œā”€ā”€ image_gen.py
    │   └── video.py
    └── requirements.txt

    Step 1: Set Up the Main App

    Create app.py with a sidebar for navigation:

    code
    import streamlit as st
    
    st.set_page_config(page_title="SANGAM AI", page_icon="šŸ¤–", layout="wide")
    st.title("šŸ¤– SANGAM AI — Your All-in-One AI Toolkit")
    
    mode = st.sidebar.selectbox(
        "Choose a Tool",
        ["Text Generation", "Text to Speech", "Image Generation", "Video Processing"]
    )
    
    if mode == "Text Generation":
        from modules.text_gen import run
        run()
    elif mode == "Text to Speech":
        from modules.tts import run
        run()
    elif mode == "Image Generation":
        from modules.image_gen import run
        run()
    else:
        from modules.video import run
        run()

    Step 2: Text Generation Module

    Create modules/text_gen.py:

    code
    import streamlit as st
    from mistralai.client import MistralClient
    from mistralai.models.chat_completion import ChatMessage
    
    def run():
        st.header("šŸ“ Text Generation")
        api_key = st.text_input("Mistral API Key", type="password")
        prompt = st.text_area("Enter your prompt:")
        if st.button("Generate") and api_key and prompt:
            client = MistralClient(api_key=api_key)
            response = client.chat(
                model="mistral-small",
                messages=[ChatMessage(role="user", content=prompt)]
            )
            st.write(response.choices[0].message.content)

    Step 3: Text-to-Speech Module

    Create modules/tts.py:

    code
    import streamlit as st
    from gtts import gTTS
    import io
    
    def run():
        st.header("šŸ”Š Text to Speech")
        text = st.text_area("Enter text to convert:")
        lang = st.selectbox("Language", ["en", "hi", "es", "fr", "de"])
        if st.button("Convert") and text:
            tts = gTTS(text=text, lang=lang)
            audio_bytes = io.BytesIO()
            tts.write_to_fp(audio_bytes)
            audio_bytes.seek(0)
            st.audio(audio_bytes, format="audio/mp3")
            st.download_button("Download Audio", audio_bytes, file_name="speech.mp3")

    Step 4: Run SANGAM AI

    code
    streamlit run app.py

    How It Works

    SANGAM AI is essentially a multi-page Streamlit app driven by st.sidebar.radio() as a router: each option renders a different module, which keeps every capability isolated in its own file. This matters as apps grow — one file per feature is far easier to debug than a single 500-line script.

    The text module calls the Mistral API with requests and reads response.json()["choices"][0]["message"]["content"]. Because API calls take seconds, the app shows st.spinner() while waiting — a small touch that massively improves perceived speed.

    The voice module passes generated text to gTTS, which returns an MP3 that Streamlit can play natively with st.audio(). The image module wraps Pillow to apply filters and resize operations on uploads. If you want to go deeper on any one capability, the dedicated text-to-speech tutorial and sentiment analysis guide cover the modules in isolation.

    Key Concepts

  • Modular design — Each AI feature lives in its own file for easy maintenance.
  • Mistral AI — Powers text generation via a simple chat API.
  • gTTS — Google Text-to-Speech converts text to MP3 audio in seconds.
  • Streamlit sidebar — Acts as the navigation menu between tools.
  • What to Try Next

  • Add chat history to the text generation module using st.session_state.
  • Deploy to Streamlit Cloud so anyone can use SANGAM AI from a browser.
  • Common Errors & Fixes

  • 401 from the Mistral API — the key is missing or misread. Load it with os.environ.get("MISTRAL_API_KEY") and confirm it is exported in the shell *before* launching Streamlit.
  • `st.audio` renders but plays nothing — gTTS returned an empty/failed response. Check the language code (e.g. "en") and print the response length to debug.
  • Image module crashes on PNG with alpha — Pillow filters sometimes require RGB. Convert first with img.convert("RGB").
  • Module state leaks between pages — widgets keep values when you switch radio options. Give widgets unique key= arguments per module.
  • FAQ

    Do I need a paid Mistral account?

    No — Mistral offers a free tier that is plenty for learning. You do need to register an API key and keep it in an environment variable.

    Can I deploy SANGAM AI to the cloud?

    Yes, Streamlit Community Cloud works. Add your API key in the app's Secrets settings rather than committing it to GitHub.

    Why split modules into separate files?

    Isolation: a crash in the image module no longer takes down chat, and you can reuse modules in other projects — the TTS module is a drop-in fit for the gTTS app.