Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
import torch
|
3 |
import numpy as np
|
4 |
import faiss
|
@@ -112,7 +114,6 @@ def generate_answer(query, context):
|
|
112 |
# ------------------------
|
113 |
# Streamlit UI
|
114 |
# ------------------------
|
115 |
-
st.set_page_config(page_title="RAG Book Analyzer", layout="wide")
|
116 |
st.title("RAG-Based Book Analyzer")
|
117 |
st.write("Upload a book (PDF, TXT, DOCX) to get a summary and ask questions about its content.")
|
118 |
|
@@ -139,7 +140,7 @@ if uploaded_file:
|
|
139 |
# Retrieve top 3 relevant chunks as context
|
140 |
query_embedding = embedder.encode([query])
|
141 |
faiss.normalize_L2(query_embedding)
|
142 |
-
distances, indices = index.search(query_embedding, k=3)
|
143 |
retrieved_chunks = [chunks[i] for i in indices[0] if i < len(chunks)]
|
144 |
context = "\n".join(retrieved_chunks)
|
145 |
answer = generate_answer(query, context)
|
|
|
1 |
import streamlit as st
|
2 |
+
st.set_page_config(page_title="RAG Book Analyzer", layout="wide") # Must be the first Streamlit command
|
3 |
+
|
4 |
import torch
|
5 |
import numpy as np
|
6 |
import faiss
|
|
|
114 |
# ------------------------
|
115 |
# Streamlit UI
|
116 |
# ------------------------
|
|
|
117 |
st.title("RAG-Based Book Analyzer")
|
118 |
st.write("Upload a book (PDF, TXT, DOCX) to get a summary and ask questions about its content.")
|
119 |
|
|
|
140 |
# Retrieve top 3 relevant chunks as context
|
141 |
query_embedding = embedder.encode([query])
|
142 |
faiss.normalize_L2(query_embedding)
|
143 |
+
distances, indices = st.session_state.index.search(query_embedding, k=3)
|
144 |
retrieved_chunks = [chunks[i] for i in indices[0] if i < len(chunks)]
|
145 |
context = "\n".join(retrieved_chunks)
|
146 |
answer = generate_answer(query, context)
|