Update lab/title_issue.py
Browse files- lab/title_issue.py +34 -2
lab/title_issue.py
CHANGED
@@ -20,6 +20,18 @@ st.title("Blah-1")
|
|
20 |
# ----------------- API Keys -----------------
|
21 |
os.environ["GROQ_API_KEY"] = st.secrets.get("GROQ_API_KEY", "")
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
# ----------------- ChromaDB Persistent Directory -----------------
|
24 |
CHROMA_DB_DIR = "/mnt/data/chroma_db"
|
25 |
os.makedirs(CHROMA_DB_DIR, exist_ok=True)
|
@@ -65,8 +77,8 @@ def extract_metadata(pdf_path):
|
|
65 |
|
66 |
return title, author, email_str, affiliation_str
|
67 |
|
68 |
-
# ----------------- PDF
|
69 |
-
pdf_source = st.radio("
|
70 |
|
71 |
if pdf_source == "Upload a PDF file":
|
72 |
uploaded_file = st.file_uploader("Upload your PDF file", type=["pdf"])
|
@@ -78,6 +90,26 @@ if pdf_source == "Upload a PDF file":
|
|
78 |
st.session_state.chunked = False
|
79 |
st.session_state.vector_created = False
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
# ----------------- Process PDF -----------------
|
82 |
if not st.session_state.pdf_loaded and "pdf_path" in st.session_state:
|
83 |
with st.spinner("π Processing document... Please wait."):
|
|
|
20 |
# ----------------- API Keys -----------------
|
21 |
os.environ["GROQ_API_KEY"] = st.secrets.get("GROQ_API_KEY", "")
|
22 |
|
23 |
+
# Load LLM models
|
24 |
+
llm_judge = ChatGroq(model="deepseek-r1-distill-llama-70b")
|
25 |
+
rag_llm = ChatGroq(model="mixtral-8x7b-32768")
|
26 |
+
|
27 |
+
llm_judge.verbose = True
|
28 |
+
rag_llm.verbose = True
|
29 |
+
|
30 |
+
# Clear ChromaDB cache to fix tenant issue
|
31 |
+
chromadb.api.client.SharedSystemClient.clear_system_cache()
|
32 |
+
|
33 |
+
st.title("Blah")
|
34 |
+
|
35 |
# ----------------- ChromaDB Persistent Directory -----------------
|
36 |
CHROMA_DB_DIR = "/mnt/data/chroma_db"
|
37 |
os.makedirs(CHROMA_DB_DIR, exist_ok=True)
|
|
|
77 |
|
78 |
return title, author, email_str, affiliation_str
|
79 |
|
80 |
+
# ----------------- Step 1: Choose PDF Source -----------------
|
81 |
+
pdf_source = st.radio("Upload or provide a link to a PDF:", ["Upload a PDF file", "Enter a PDF URL"], index=0, horizontal=True)
|
82 |
|
83 |
if pdf_source == "Upload a PDF file":
|
84 |
uploaded_file = st.file_uploader("Upload your PDF file", type=["pdf"])
|
|
|
90 |
st.session_state.chunked = False
|
91 |
st.session_state.vector_created = False
|
92 |
|
93 |
+
elif pdf_source == "Enter a PDF URL":
|
94 |
+
pdf_url = st.text_input("Enter PDF URL:")
|
95 |
+
if pdf_url and not st.session_state.pdf_loaded:
|
96 |
+
with st.spinner("π Downloading PDF..."):
|
97 |
+
try:
|
98 |
+
response = requests.get(pdf_url)
|
99 |
+
if response.status_code == 200:
|
100 |
+
st.session_state.pdf_path = "/mnt/data/temp.pdf"
|
101 |
+
with open(st.session_state.pdf_path, "wb") as f:
|
102 |
+
f.write(response.content)
|
103 |
+
st.session_state.pdf_loaded = False
|
104 |
+
st.session_state.chunked = False
|
105 |
+
st.session_state.vector_created = False
|
106 |
+
st.success("β
PDF Downloaded Successfully!")
|
107 |
+
else:
|
108 |
+
st.error("β Failed to download PDF. Check the URL.")
|
109 |
+
except Exception as e:
|
110 |
+
st.error(f"Error downloading PDF: {e}")
|
111 |
+
|
112 |
+
|
113 |
# ----------------- Process PDF -----------------
|
114 |
if not st.session_state.pdf_loaded and "pdf_path" in st.session_state:
|
115 |
with st.spinner("π Processing document... Please wait."):
|