Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -3,11 +3,16 @@ from src.file_loader import load_file
|
|
| 3 |
from src.rag_pipeline import build_rag_pipeline, get_relevant_docs
|
| 4 |
from src.model_utils import load_hf_model, generate_answer
|
| 5 |
from src.utils import get_font_css
|
|
|
|
| 6 |
|
| 7 |
st.set_page_config(page_title="AI Chatbot", page_icon=":robot_face:", layout="wide")
|
| 8 |
st.markdown(get_font_css(), unsafe_allow_html=True)
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
st.sidebar.title("AI Chatbot")
|
| 12 |
st.sidebar.markdown("Upload a file to get started:")
|
| 13 |
|
|
@@ -38,7 +43,7 @@ st.markdown(
|
|
| 38 |
if uploaded_file:
|
| 39 |
with st.spinner("Processing file..."):
|
| 40 |
text = load_file(uploaded_file)
|
| 41 |
-
docs = [
|
| 42 |
retriever = build_rag_pipeline(docs, embedding_model)
|
| 43 |
st.success("File processed and indexed!")
|
| 44 |
|
|
@@ -53,7 +58,7 @@ if uploaded_file:
|
|
| 53 |
if st.button("Send", use_container_width=True) and user_input:
|
| 54 |
with st.spinner("Generating answer..."):
|
| 55 |
context_docs = get_relevant_docs(retriever, user_input)
|
| 56 |
-
context = " ".join([doc
|
| 57 |
answer = generate_answer(text_gen, user_input, context)
|
| 58 |
st.session_state.chat_history.append(("user", user_input))
|
| 59 |
st.session_state.chat_history.append(("bot", answer))
|
|
|
|
| 3 |
from src.rag_pipeline import build_rag_pipeline, get_relevant_docs
|
| 4 |
from src.model_utils import load_hf_model, generate_answer
|
| 5 |
from src.utils import get_font_css
|
| 6 |
+
from langchain.schema import Document
|
| 7 |
|
| 8 |
st.set_page_config(page_title="AI Chatbot", page_icon=":robot_face:", layout="wide")
|
| 9 |
st.markdown(get_font_css(), unsafe_allow_html=True)
|
| 10 |
|
| 11 |
+
try:
|
| 12 |
+
st.sidebar.image("assets/logo.png", width=180)
|
| 13 |
+
except Exception:
|
| 14 |
+
st.sidebar.write("AI Chatbot")
|
| 15 |
+
|
| 16 |
st.sidebar.title("AI Chatbot")
|
| 17 |
st.sidebar.markdown("Upload a file to get started:")
|
| 18 |
|
|
|
|
| 43 |
if uploaded_file:
|
| 44 |
with st.spinner("Processing file..."):
|
| 45 |
text = load_file(uploaded_file)
|
| 46 |
+
docs = [Document(page_content=chunk, metadata={}) for chunk in text]
|
| 47 |
retriever = build_rag_pipeline(docs, embedding_model)
|
| 48 |
st.success("File processed and indexed!")
|
| 49 |
|
|
|
|
| 58 |
if st.button("Send", use_container_width=True) and user_input:
|
| 59 |
with st.spinner("Generating answer..."):
|
| 60 |
context_docs = get_relevant_docs(retriever, user_input)
|
| 61 |
+
context = " ".join([doc.page_content for doc in context_docs])
|
| 62 |
answer = generate_answer(text_gen, user_input, context)
|
| 63 |
st.session_state.chat_history.append(("user", user_input))
|
| 64 |
st.session_state.chat_history.append(("bot", answer))
|