Documentation Index
Fetch the complete documentation index at: https://mintlify.com/diazdavilajesus16-stack/IA-LUMINA/llms.txt
Use this file to discover all available pages before exploring further.
Main.py is the Streamlit entry point for Lumina AI and contains several helper functions for audio transcription, text-to-speech synthesis, PDF text extraction, and image encoding. These functions are independent of the chat logic and can be reused or extended for custom integrations.
transcribe_audio
Transcribes raw audio bytes to text using the Google Speech Recognition API.Raw audio file contents as a bytes object. The function attempts to handle any audio format supported by pydub when it is available.
- Uses
SpeechRecognitionwithlanguage="es-ES"(Spanish, Spain). - If
pydubis installed, the function converts the input bytes to WAV format before recognition, enabling support for WebM and other browser-recorded formats. - If
pydubis not available, the bytes are written to a temporary.webmfile and passed directly to the recognizer.
Non-WAV audio formats require
ffmpeg to be installed and accessible on your system PATH. If ffmpeg is missing, the function displays a Streamlit warning and returns an empty string.text_to_speech
Synthesizes text to an MP3 audio file using Google Text-to-Speech.The text string to synthesize. Passed directly to gTTS without preprocessing.
.mp3 file containing the synthesized audio, or None if synthesis fails. The temporary file is created with tempfile.NamedTemporaryFile and is not automatically deleted — it persists until the operating system cleans up the temp directory.
Uses gTTS with lang="es" (Spanish).
extract_text_from_pdf
Extracts all text content from an uploaded PDF file.A file-like object pointing to a PDF. In the Streamlit context this is a
UploadedFile from st.file_uploader, but any object accepted by PyPDF2.PdfReader works.PyPDF2.PdfReader to iterate all pages and call page.extract_text() on each.
query_pdf
Searches extracted PDF text for the paragraph most relevant to a question.The user’s question. Word tokens are extracted with
re.findall(r'\w+', ...) and matched case-insensitively against paragraph content.Full text string returned by
extract_text_from_pdf. An empty string causes the function to return None immediately.None if no paragraph scores at least 2 matching question words.
The return format is:
....
Algorithm:
- Split
pdf_texton blank lines (\n\s*\n) to produce a list of paragraphs. - For each paragraph, count how many unique question words appear in it.
- Return the paragraph with the highest score, provided that score is
>= 2.
get_img_base64
Reads an image file and returns it as a data URI string for use in HTML.Absolute or relative path to the image file. The MIME type is determined by the file extension.
| Extension | MIME type |
|---|---|
.png | image/png |
.jpg, .jpeg | image/jpeg |
| anything else | image/png (default) |
st.error message is also displayed when the file is missing.