Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -252,17 +252,44 @@ with gr.Blocks(title="NRL Chat for Commercial procurement", theme=gr.themes.Soft
|
|
| 252 |
index_status = gr.Markdown("📊 Status: Ready")
|
| 253 |
|
| 254 |
# Store uploaded files
|
|
|
|
| 255 |
def store_files(files):
|
| 256 |
file_dict = {}
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
return file_dict
|
| 264 |
|
| 265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
# RIGHT COLUMN: QA Interface
|
| 268 |
with gr.Column(scale=2):
|
|
|
|
| 252 |
index_status = gr.Markdown("📊 Status: Ready")
|
| 253 |
|
| 254 |
# Store uploaded files
|
| 255 |
+
# Store uploaded files - CORRECTED VERSION
|
| 256 |
def store_files(files):
|
| 257 |
file_dict = {}
|
| 258 |
+
if not files:
|
| 259 |
+
return {}
|
| 260 |
+
|
| 261 |
+
for file_obj in files:
|
| 262 |
+
if file_obj and hasattr(file_obj, 'name'):
|
| 263 |
+
source_path = file_obj.name # This is the string path
|
| 264 |
+
|
| 265 |
+
# Create temp copy with original name
|
| 266 |
+
temp_suffix = os.path.splitext(file_obj.name)[1] or '.pdf'
|
| 267 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=temp_suffix) as tmp:
|
| 268 |
+
# Read from file path, not file object
|
| 269 |
+
with open(source_path, 'rb') as source_file:
|
| 270 |
+
shutil.copyfileobj(source_file, tmp)
|
| 271 |
+
file_dict[file_obj.name] = tmp.name
|
| 272 |
+
|
| 273 |
return file_dict
|
| 274 |
|
| 275 |
+
# Update the event handler
|
| 276 |
+
pdf_upload.change(
|
| 277 |
+
store_files,
|
| 278 |
+
inputs=pdf_upload,
|
| 279 |
+
outputs=uploaded_files
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
#def store_files(files):
|
| 283 |
+
# file_dict = {}
|
| 284 |
+
# for f in files:
|
| 285 |
+
# if f:
|
| 286 |
+
# with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
|
| 287 |
+
# tmp.write(f.read())
|
| 288 |
+
# tmp.close() # Explicit close
|
| 289 |
+
# file_dict[f.name] = tmp.name
|
| 290 |
+
# return file_dict
|
| 291 |
+
#
|
| 292 |
+
#pdf_upload.change(store_files, pdf_upload, uploaded_files)
|
| 293 |
|
| 294 |
# RIGHT COLUMN: QA Interface
|
| 295 |
with gr.Column(scale=2):
|