sunbal7 commited on
Commit
a7e018f
Β·
verified Β·
1 Parent(s): 3231f25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -67,8 +67,8 @@ def generate_response(query, context):
67
  return tokenizer.batch_decode(output, skip_special_tokens=True)[0]
68
 
69
  # Streamlit UI
70
- st.set_page_config(page_title="πŸ“– RAG-Based AI", page_icon="πŸ€–")
71
- st.title("πŸ“– RAG-based Q&A using IBM Granite")
72
  st.subheader("Upload documents and ask questions!")
73
 
74
  uploaded_files = st.file_uploader("Upload PDFs or TXT files", accept_multiple_files=True)
@@ -78,10 +78,13 @@ if uploaded_files:
78
  process_documents(uploaded_files)
79
  st.success("Documents uploaded and indexed!")
80
 
81
- query = st.text_input("Ask a question:")
82
- if st.button("Get Answer"):
83
- with st.spinner("Retrieving and generating response..."):
84
- context = retrieve_context(query)
85
- response = generate_response(query, context)
86
- st.markdown("### πŸ€– Answer:")
87
- st.write(response)
 
 
 
 
67
  return tokenizer.batch_decode(output, skip_special_tokens=True)[0]
68
 
69
  # Streamlit UI
70
+ st.set_page_config(page_title="πŸ“– Smart Study", page_icon="πŸ€–")
71
+ st.title("πŸ“– Q&A using IBM Granite")
72
  st.subheader("Upload documents and ask questions!")
73
 
74
  uploaded_files = st.file_uploader("Upload PDFs or TXT files", accept_multiple_files=True)
 
78
  process_documents(uploaded_files)
79
  st.success("Documents uploaded and indexed!")
80
 
81
+ if query:
82
+ if index.ntotal == 0: # Ensure documents are indexed before querying
83
+ st.warning("Please upload and process documents first!")
84
+ else:
85
+ with st.spinner("Retrieving and generating response..."):
86
+ context = retrieve_context(query)
87
+ response = generate_response(query, context)
88
+ st.markdown("### πŸ€– Answer:")
89
+ st.write(response)
90
+