DrishtiSharma's picture
Update app.py
a9e6c3b verified
raw
history blame
1.87 kB
# 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")
llm_judge.verbose = True
rag_llm.verbose = True
# Clear ChromaDB cache to fix tenant issue
chromadb.api.client.SharedSystemClient.clear_system_cache()
st.title("Blah - 1")
# 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, horizontal=True)
if pdf_source == "Upload a PDF file":
uploaded_file = st.file_uploader("Upload your PDF file", type="pdf")
if uploaded_file:
st.session_state.pdf_path = "temp.pdf"
with open(st.session_state.pdf_path, "wb") as f:
f.write(uploaded_file.getbuffer())
st.session_state.pdf_loaded = False
st.session_state.chunked = False
st.session_state.vector_created = False
elif pdf_source == "Enter a PDF URL":
pdf_url = st.text_input("Enter PDF URL:")
if pdf_url and not st.session_state.get("pdf_loaded", False):
with st.spinner("Downloading PDF..."):
try:
response = requests.get(pdf_url)
if response.status_code == 200:
st.session_state.pdf_path = "temp.pdf"
with open(st.session_state.pdf_path, "wb") as f:
f.write(response.content)
st.session_state.pdf_loaded = False
st.session_state.chunked = False
st.session_state.vector_created = False
st.success("βœ… PDF Downloaded Successfully!")
else:
st.error("❌ Failed to download PDF. Check the URL.")
except Exception as e:
st.error(f"Error downloading PDF: {e}")