Spaces:
Sleeping
Sleeping
WebashalarForML
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -74,20 +74,38 @@ def upload_file():
|
|
74 |
logging.info(f"Files successfully uploaded: {uploaded_files}")
|
75 |
return redirect(url_for('index'))
|
76 |
|
77 |
-
@app.route('/remove_file')
|
78 |
def remove_file():
|
79 |
uploaded_files = session.get('uploaded_files', [])
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
os.
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
return redirect(url_for('index'))
|
92 |
|
93 |
@app.route('/process', methods=['POST'])
|
|
|
74 |
logging.info(f"Files successfully uploaded: {uploaded_files}")
|
75 |
return redirect(url_for('index'))
|
76 |
|
77 |
+
@app.route('/remove_file',methods=['POST'])
|
78 |
def remove_file():
|
79 |
uploaded_files = session.get('uploaded_files', [])
|
80 |
+
if uploaded_file:
|
81 |
+
for filename in uploaded_files:
|
82 |
+
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
83 |
+
if os.path.exists(file_path):
|
84 |
+
os.remove(file_path)
|
85 |
+
logging.info(f"Removed file: {filename}")
|
86 |
+
else:
|
87 |
+
logging.warning(f"File not found for removal: {file_path}") # More specific log
|
88 |
+
|
89 |
+
session.pop('uploaded_files', None)
|
90 |
+
flash('Files successfully removed')
|
91 |
+
logging.info("All uploaded files removed")
|
92 |
+
else:
|
93 |
+
flash('No file to remove.')
|
94 |
+
logging.warning(f"File not found for removal: {file_path")
|
95 |
+
return redirect(url_for('index'))
|
96 |
|
97 |
+
@app.route('/reset_upload')
|
98 |
+
def reset_upload():
|
99 |
+
"""Reset the uploaded file and the processed data."""
|
100 |
+
uploaded_file = session.get('uploaded_file', [])
|
101 |
+
if uploaded_file:
|
102 |
+
for filename in uploaded_file:
|
103 |
+
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
104 |
+
logging.info(f"Removed file: {filename}")
|
105 |
+
session.pop('uploaded_files', None)
|
106 |
+
flash('Files successfully removed')
|
107 |
+
else:
|
108 |
+
flash('No file to remove.')
|
109 |
return redirect(url_for('index'))
|
110 |
|
111 |
@app.route('/process', methods=['POST'])
|