tbaig1605 commited on
Commit
2a85dd6
Β·
verified Β·
1 Parent(s): d24b094

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  import docx
 
3
  import numpy as np
4
  import streamlit as st
5
  from sentence_transformers import SentenceTransformer
@@ -19,12 +20,12 @@ st.set_page_config(page_title="Word RAG App", layout="wide")
19
  st.title("πŸ“„ Word Document RAG")
20
 
21
  uploaded_file = st.file_uploader(
22
- "Upload a Word document",
23
  type=["docx"]
24
  )
25
 
26
  # ==========================================================
27
- # WORD TEXT EXTRACTION (UNCHANGED LOGIC)
28
  # ==========================================================
29
  def read_word(doc_path):
30
  doc = docx.Document(doc_path)
@@ -95,7 +96,7 @@ def generate_answer(query, context):
95
  You are a document-based assistant.
96
  Use the context to answer the question clearly.
97
  If the answer is partially available, summarize it.
98
- If the answer is not present, you may say 'Not found in the document'.
99
 
100
  Context:
101
  {context}
@@ -114,12 +115,12 @@ def generate_answer(query, context):
114
  # APP LOGIC
115
  # ==========================================================
116
  if uploaded_file:
117
- with st.spinner("πŸ“„ Reading Word document..."):
118
- file_name = uploaded_file.name
119
- with open(file_name, "wb") as f:
120
  f.write(uploaded_file.getbuffer())
121
 
122
- pages = read_word(file_name)
123
 
124
  with st.spinner("βœ‚οΈ Chunking & embedding document..."):
125
  chunks = chunk_text(pages)
@@ -139,3 +140,4 @@ if uploaded_file:
139
 
140
  st.markdown("### βœ… Answer")
141
  st.write(answer)
 
 
1
  import os
2
  import docx
3
+ import pandas as pd
4
  import numpy as np
5
  import streamlit as st
6
  from sentence_transformers import SentenceTransformer
 
20
  st.title("πŸ“„ Word Document RAG")
21
 
22
  uploaded_file = st.file_uploader(
23
+ "Upload a Word document (.docx)",
24
  type=["docx"]
25
  )
26
 
27
  # ==========================================================
28
+ # WORD TEXT EXTRACTION (UNCHANGED)
29
  # ==========================================================
30
  def read_word(doc_path):
31
  doc = docx.Document(doc_path)
 
96
  You are a document-based assistant.
97
  Use the context to answer the question clearly.
98
  If the answer is partially available, summarize it.
99
+ If the answer is not present, say 'Not found in the document'.
100
 
101
  Context:
102
  {context}
 
115
  # APP LOGIC
116
  # ==========================================================
117
  if uploaded_file:
118
+ with st.spinner("πŸ“„ Reading document..."):
119
+ temp_path = "/tmp/uploaded.docx"
120
+ with open(temp_path, "wb") as f:
121
  f.write(uploaded_file.getbuffer())
122
 
123
+ pages = read_word(temp_path)
124
 
125
  with st.spinner("βœ‚οΈ Chunking & embedding document..."):
126
  chunks = chunk_text(pages)
 
140
 
141
  st.markdown("### βœ… Answer")
142
  st.write(answer)
143
+