dev-models commited on
Commit
0fe8565
·
1 Parent(s): e52c8f5

app file updated

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -8,6 +8,7 @@ import time
8
  # Import Modular components
9
  from backend.rag import RAGEngine
10
  from backend.parser import EnrichedRagParser
 
11
 
12
  # ==========================================
13
  # 1. Page Configuration & Professional CSS
@@ -105,18 +106,23 @@ def main():
105
 
106
  if uploaded_file:
107
  # Temporary save for parsing
108
- temp_dir = "/tmp"
109
- os.makedirs(temp_dir, exist_ok=True)
110
- save_path = os.path.join(temp_dir, uploaded_file.name)
 
 
 
 
 
 
 
111
 
112
- with open(save_path, "wb") as f:
113
- f.write(uploaded_file.getbuffer())
114
 
115
  if st.button("🚀 Process PDF", type="primary", use_container_width=True):
116
  try:
117
  with st.spinner("Analyzing PDF with Docling..."):
118
  parser = EnrichedRagParser()
119
- parsed_data = parser.process_document(save_path)
120
 
121
  with st.spinner("Ingesting into MongoDB..."):
122
  rag.ingest_data(parsed_data)
@@ -131,10 +137,10 @@ def main():
131
  st.error(f"❌ Error: {str(e)}")
132
 
133
  finally:
134
- # ✅ Always cleanup temp file
135
- if os.path.exists(save_path):
136
- os.remove(save_path)
137
- print("🧹 Temp file deleted")
138
 
139
  st.rerun()
140
  st.markdown("---")
 
8
  # Import Modular components
9
  from backend.rag import RAGEngine
10
  from backend.parser import EnrichedRagParser
11
+ import tempfile
12
 
13
  # ==========================================
14
  # 1. Page Configuration & Professional CSS
 
106
 
107
  if uploaded_file:
108
  # Temporary save for parsing
109
+ # temp_dir = "/tmp"
110
+ # os.makedirs(temp_dir, exist_ok=True)
111
+ # save_path = os.path.join(temp_dir, uploaded_file.name)
112
+
113
+ # with open(save_path, "wb") as f:
114
+ # f.write(uploaded_file.getbuffer())
115
+
116
+ with tempfile.NamedTemporaryFile(delete=False) as tmp:
117
+ tmp.write(uploaded_file.read())
118
+ file_path = tmp.name
119
 
 
 
120
 
121
  if st.button("🚀 Process PDF", type="primary", use_container_width=True):
122
  try:
123
  with st.spinner("Analyzing PDF with Docling..."):
124
  parser = EnrichedRagParser()
125
+ parsed_data = parser.process_document(file_path)
126
 
127
  with st.spinner("Ingesting into MongoDB..."):
128
  rag.ingest_data(parsed_data)
 
137
  st.error(f"❌ Error: {str(e)}")
138
 
139
  finally:
140
+ # # ✅ Always cleanup temp file
141
+ # if os.path.exists(file_path):
142
+ # os.remove(file_path)
143
+ print("🧹 Temp file deleted")
144
 
145
  st.rerun()
146
  st.markdown("---")