import streamlit as st import os import re from langchain_google_genai import ChatGoogleGenerativeAI from langchain_text_splitters import RecursiveCharacterTextSplitter from langchain_community.vectorstores import FAISS from langchain_core.prompts import PromptTemplate from langchain_community.embeddings import HuggingFaceEmbeddings from dotenv import load_dotenv from unstructured.partition.auto import partition # ==================== ENV SETUP ==================== load_dotenv() if not os.getenv("GOOGLE_API_KEY"): st.error("❌ GOOGLE_API_KEY not found. Add it in Hugging Face Secrets.") st.stop() # Disable inference for safety (you can remove this in Docker if you want full inference) os.environ["UNSTRUCTURED_DISABLE_INFERENCE"] = "true" # ==================== QUESTION SPLITTER ==================== def split_questions(text): text = text.replace("\n", " ").strip() # Split on ? OR . only if the dot is NOT part of a number like "1." questions = re.split( r'(?