File size: 1,762 Bytes
aa31b3b
 
1f85d80
8858519
 
 
aa31b3b
 
 
 
8858519
aa31b3b
 
 
 
8858519
 
b604a12
 
 
5a1233f
07386f9
b604a12
 
 
 
 
 
 
 
 
 
 
5a1233f
 
 
 
 
 
 
 
 
 
 
 
 
b604a12
 
 
5a1233f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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", "Enter a PDF URL"], index=0)

if pdf_source == "Upload a PDF":
    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