vishalkatheriya commited on
Commit
1302559
Β·
verified Β·
1 Parent(s): 9e2c8ce

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +4 -18
src/streamlit_app.py CHANGED
@@ -66,35 +66,21 @@ def extract_text_from_pdf(file_bytes):
66
  return text
67
  with tab1:
68
  st.subheader("Upload and index PDFs")
69
-
70
- files = st.file_uploader(
71
- "Choose PDF files",
72
- type=["pdf"],
73
- accept_multiple_files=True
74
- )
75
-
76
  if st.button("Index PDFs"):
77
  if not files:
78
  st.warning("Select at least one PDF.")
79
  else:
80
  reset_index()
81
  results = []
82
-
83
  for f in files:
 
 
84
  try:
85
- file_bytes = f.getvalue()
86
-
87
- # βœ… Extract text directly (no saving)
88
- text = extract_text_from_pdf(file_bytes)
89
-
90
- # βœ… Now index directly into DB
91
- n = index_text(text, source_name=f.name)
92
-
93
  results.append(f"βœ… {f.name}: {n} chunks indexed")
94
-
95
  except Exception as e:
96
  results.append(f"❌ {f.name}: Error β€” {e}")
97
-
98
  st.success("\n".join(results))
99
 
100
  # ── Tab 2: Chat ───────────────────────────────────────────────────
 
66
  return text
67
  with tab1:
68
  st.subheader("Upload and index PDFs")
69
+ files = st.file_uploader("Choose PDF files", type=["pdf"], accept_multiple_files=True)
 
 
 
 
 
 
70
  if st.button("Index PDFs"):
71
  if not files:
72
  st.warning("Select at least one PDF.")
73
  else:
74
  reset_index()
75
  results = []
 
76
  for f in files:
77
+ dest = UPLOADS_DIR / f.name
78
+ dest.write_bytes(f.getvalue())
79
  try:
80
+ n = index_pdf(dest, source_name=f.name)
 
 
 
 
 
 
 
81
  results.append(f"βœ… {f.name}: {n} chunks indexed")
 
82
  except Exception as e:
83
  results.append(f"❌ {f.name}: Error β€” {e}")
 
84
  st.success("\n".join(results))
85
 
86
  # ── Tab 2: Chat ───────────────────────────────────────────────────