Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,13 +8,19 @@ def upload_pdfs(files: List[gr.File]):
|
|
8 |
"""
|
9 |
try:
|
10 |
os.makedirs("uploaded_pdfs", exist_ok=True)
|
|
|
11 |
for file in files:
|
12 |
if file.name.endswith(".pdf"):
|
13 |
file_path = os.path.join("uploaded_pdfs", file.name)
|
14 |
-
|
|
|
|
|
15 |
else:
|
16 |
return f"Error: {file.name} is not a PDF file."
|
17 |
-
|
|
|
|
|
|
|
18 |
except Exception as e:
|
19 |
return f"Error uploading files: {str(e)}"
|
20 |
|
|
|
8 |
"""
|
9 |
try:
|
10 |
os.makedirs("uploaded_pdfs", exist_ok=True)
|
11 |
+
saved_files = []
|
12 |
for file in files:
|
13 |
if file.name.endswith(".pdf"):
|
14 |
file_path = os.path.join("uploaded_pdfs", file.name)
|
15 |
+
with open(file_path, "wb") as f:
|
16 |
+
f.write(file.getvalue())
|
17 |
+
saved_files.append(file.name)
|
18 |
else:
|
19 |
return f"Error: {file.name} is not a PDF file."
|
20 |
+
if saved_files:
|
21 |
+
return f"Saved {len(saved_files)} PDF files to the 'uploaded_pdfs' directory."
|
22 |
+
else:
|
23 |
+
return "No PDF files were uploaded."
|
24 |
except Exception as e:
|
25 |
return f"Error uploading files: {str(e)}"
|
26 |
|