import os import requests import streamlit as st from langchain.chains import SequentialChain, LLMChain from langchain.prompts import PromptTemplate from langchain_groq import ChatGroq from langchain.document_loaders import PDFPlumberLoader from langchain_experimental.text_splitter import SemanticChunker from langchain_huggingface import HuggingFaceEmbeddings from langchain_chroma import Chroma # Set API Keys os.environ["GROQ_API_KEY"] = st.secrets.get("GROQ_API_KEY", "") # Load LLM models llm_judge = ChatGroq(model="deepseek-r1-distill-llama-70b") rag_llm = ChatGroq(model="mixtral-8x7b-32768") st.title("❓") # Step 1: Choose PDF Source pdf_source = st.radio("Upload or provide a link to a PDF:", ["Upload a PDF file", "Enter a PDF URL"], index=0) if pdf_source == "Upload a PDF file": uploaded_file = st.file_uploader("Upload your PDF file", type="pdf") if uploaded_file: with open("temp.pdf", "wb") as f: f.write(uploaded_file.getbuffer()) pdf_path = "temp.pdf" elif pdf_source == "Enter a PDF URL": pdf_url = st.text_input("Enter PDF URL:") if pdf_url: with st.spinner("Downloading PDF..."): try: response = requests.get(pdf_url) if response.status_code == 200: with open("temp.pdf", "wb") as f: f.write(response.content) pdf_path = "temp.pdf" st.success("✅ PDF Downloaded Successfully!") else: st.error("❌ Failed to download PDF. Check the URL.") pdf_path = None except Exception as e: st.error(f"Error downloading PDF: {e}") pdf_path = None else: pdf_path = None