Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,7 +52,8 @@ def allowed_file(filename):
|
|
| 52 |
|
| 53 |
@app.route('/')
|
| 54 |
def index():
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
@app.route('/guide')
|
| 58 |
def guide():
|
|
@@ -76,6 +77,7 @@ def text_preview():
|
|
| 76 |
resume_file_path = os.path.join(app.config['DATA_FOLDER'], 'resume_text.txt')
|
| 77 |
if not os.path.exists(resume_file_path):
|
| 78 |
flash('Resume text not found', 'error')
|
|
|
|
| 79 |
return redirect(url_for('index'))
|
| 80 |
|
| 81 |
with open(resume_file_path, 'r') as f:
|
|
@@ -83,6 +85,7 @@ def text_preview():
|
|
| 83 |
return render_template('text.html', text=text)
|
| 84 |
except Exception as e:
|
| 85 |
flash(f"Error loading text preview: {str(e)}", 'error')
|
|
|
|
| 86 |
return redirect(url_for('index'))
|
| 87 |
|
| 88 |
@app.route('/upload', methods=['GET', 'POST'])
|
|
@@ -91,11 +94,13 @@ def upload_file():
|
|
| 91 |
if request.method == 'POST':
|
| 92 |
if 'file' not in request.files:
|
| 93 |
flash('No file part', 'error')
|
|
|
|
| 94 |
return render_template('upload.html') # Avoid redirect loop
|
| 95 |
|
| 96 |
file = request.files['file']
|
| 97 |
if file.filename == '':
|
| 98 |
flash('No selected file', 'error')
|
|
|
|
| 99 |
return render_template('upload.html') # Avoid redirect loop
|
| 100 |
|
| 101 |
if file and allowed_file(file.filename):
|
|
@@ -118,9 +123,11 @@ def upload_file():
|
|
| 118 |
return process_other_files(file_path, filename)
|
| 119 |
else:
|
| 120 |
flash('JSON file uploaded successfully', 'success')
|
|
|
|
| 121 |
return render_template('upload.html')
|
| 122 |
|
| 123 |
flash('File type not allowed', 'error')
|
|
|
|
| 124 |
return render_template('upload.html')
|
| 125 |
|
| 126 |
return render_template('upload.html')
|
|
@@ -144,6 +151,7 @@ def process_other_files(file_path, filename):
|
|
| 144 |
return render_template('text.html', text=cleaned_text)
|
| 145 |
except Exception as e:
|
| 146 |
flash(f"Error processing file {filename}: {str(e)}", 'error')
|
|
|
|
| 147 |
return redirect(request.referrer)
|
| 148 |
|
| 149 |
@app.route('/download', methods=['GET'])
|
|
@@ -152,6 +160,7 @@ def download_file():
|
|
| 152 |
return send_from_directory(app.config['DATA_FOLDER'], 'resume_text.txt', as_attachment=True)
|
| 153 |
except Exception as e:
|
| 154 |
flash(f"Error downloading file: {str(e)}", 'error')
|
|
|
|
| 155 |
return redirect(request.referrer)
|
| 156 |
|
| 157 |
@app.route('/download_model', methods=['GET'])
|
|
@@ -162,6 +171,7 @@ def download_latest_model():
|
|
| 162 |
|
| 163 |
if not model_files:
|
| 164 |
flash('No model files found', 'error')
|
|
|
|
| 165 |
return redirect(request.referrer)
|
| 166 |
|
| 167 |
latest_model_file = sorted(model_files, reverse=True)[0]
|
|
@@ -169,6 +179,7 @@ def download_latest_model():
|
|
| 169 |
|
| 170 |
if not os.path.exists(model_path):
|
| 171 |
flash('Model file not found on the server', 'error')
|
|
|
|
| 172 |
return redirect(request.referrer)
|
| 173 |
|
| 174 |
zip_filename = os.path.join(models_dir, f"{latest_model_file}.zip")
|
|
@@ -179,6 +190,7 @@ def download_latest_model():
|
|
| 179 |
return send_file(zip_filename, as_attachment=True)
|
| 180 |
except Exception as e:
|
| 181 |
flash(f"Error while downloading the model: {str(e)}", 'error')
|
|
|
|
| 182 |
return redirect(request.referrer)
|
| 183 |
|
| 184 |
@app.route('/remove_file', methods=['POST'])
|
|
@@ -190,13 +202,17 @@ def remove_file():
|
|
| 190 |
if os.path.exists(file_path):
|
| 191 |
os.remove(file_path)
|
| 192 |
flash(f"{file_to_remove} removed successfully.", "success")
|
|
|
|
| 193 |
session.pop('uploaded_file', None)
|
| 194 |
else:
|
| 195 |
flash("File not found.", "error")
|
|
|
|
| 196 |
else:
|
| 197 |
flash("No file selected for removal.", "error")
|
|
|
|
| 198 |
except Exception as e:
|
| 199 |
flash(f"Error while removing file: {str(e)}", "error")
|
|
|
|
| 200 |
return redirect(url_for('upload_file'))
|
| 201 |
|
| 202 |
# Route to serve uploaded files
|
|
|
|
| 52 |
|
| 53 |
@app.route('/')
|
| 54 |
def index():
|
| 55 |
+
uploaded_file = session.get('uploaded_file', None)
|
| 56 |
+
return render_template('upload.html',uploaded_file)
|
| 57 |
|
| 58 |
@app.route('/guide')
|
| 59 |
def guide():
|
|
|
|
| 77 |
resume_file_path = os.path.join(app.config['DATA_FOLDER'], 'resume_text.txt')
|
| 78 |
if not os.path.exists(resume_file_path):
|
| 79 |
flash('Resume text not found', 'error')
|
| 80 |
+
print('Resume text not found')
|
| 81 |
return redirect(url_for('index'))
|
| 82 |
|
| 83 |
with open(resume_file_path, 'r') as f:
|
|
|
|
| 85 |
return render_template('text.html', text=text)
|
| 86 |
except Exception as e:
|
| 87 |
flash(f"Error loading text preview: {str(e)}", 'error')
|
| 88 |
+
print(f"Error loading text preview: {str(e)}")
|
| 89 |
return redirect(url_for('index'))
|
| 90 |
|
| 91 |
@app.route('/upload', methods=['GET', 'POST'])
|
|
|
|
| 94 |
if request.method == 'POST':
|
| 95 |
if 'file' not in request.files:
|
| 96 |
flash('No file part', 'error')
|
| 97 |
+
print('No file part to upload')
|
| 98 |
return render_template('upload.html') # Avoid redirect loop
|
| 99 |
|
| 100 |
file = request.files['file']
|
| 101 |
if file.filename == '':
|
| 102 |
flash('No selected file', 'error')
|
| 103 |
+
print('No selected file to upload')
|
| 104 |
return render_template('upload.html') # Avoid redirect loop
|
| 105 |
|
| 106 |
if file and allowed_file(file.filename):
|
|
|
|
| 123 |
return process_other_files(file_path, filename)
|
| 124 |
else:
|
| 125 |
flash('JSON file uploaded successfully', 'success')
|
| 126 |
+
print('JSON file uploaded successfully')
|
| 127 |
return render_template('upload.html')
|
| 128 |
|
| 129 |
flash('File type not allowed', 'error')
|
| 130 |
+
print('File type not allowed')
|
| 131 |
return render_template('upload.html')
|
| 132 |
|
| 133 |
return render_template('upload.html')
|
|
|
|
| 151 |
return render_template('text.html', text=cleaned_text)
|
| 152 |
except Exception as e:
|
| 153 |
flash(f"Error processing file {filename}: {str(e)}", 'error')
|
| 154 |
+
print(f"Error processing file {filename}: {str(e)}")
|
| 155 |
return redirect(request.referrer)
|
| 156 |
|
| 157 |
@app.route('/download', methods=['GET'])
|
|
|
|
| 160 |
return send_from_directory(app.config['DATA_FOLDER'], 'resume_text.txt', as_attachment=True)
|
| 161 |
except Exception as e:
|
| 162 |
flash(f"Error downloading file: {str(e)}", 'error')
|
| 163 |
+
print(f"Error downloading file: {str(e)}")
|
| 164 |
return redirect(request.referrer)
|
| 165 |
|
| 166 |
@app.route('/download_model', methods=['GET'])
|
|
|
|
| 171 |
|
| 172 |
if not model_files:
|
| 173 |
flash('No model files found', 'error')
|
| 174 |
+
print('No model files found')
|
| 175 |
return redirect(request.referrer)
|
| 176 |
|
| 177 |
latest_model_file = sorted(model_files, reverse=True)[0]
|
|
|
|
| 179 |
|
| 180 |
if not os.path.exists(model_path):
|
| 181 |
flash('Model file not found on the server', 'error')
|
| 182 |
+
print('Model file not found on the server')
|
| 183 |
return redirect(request.referrer)
|
| 184 |
|
| 185 |
zip_filename = os.path.join(models_dir, f"{latest_model_file}.zip")
|
|
|
|
| 190 |
return send_file(zip_filename, as_attachment=True)
|
| 191 |
except Exception as e:
|
| 192 |
flash(f"Error while downloading the model: {str(e)}", 'error')
|
| 193 |
+
print(f"Error while downloading the model: {str(e)}")
|
| 194 |
return redirect(request.referrer)
|
| 195 |
|
| 196 |
@app.route('/remove_file', methods=['POST'])
|
|
|
|
| 202 |
if os.path.exists(file_path):
|
| 203 |
os.remove(file_path)
|
| 204 |
flash(f"{file_to_remove} removed successfully.", "success")
|
| 205 |
+
print(f"{file_to_remove} removed successfully.")
|
| 206 |
session.pop('uploaded_file', None)
|
| 207 |
else:
|
| 208 |
flash("File not found.", "error")
|
| 209 |
+
print("File not found.")
|
| 210 |
else:
|
| 211 |
flash("No file selected for removal.", "error")
|
| 212 |
+
print("No file selected for removal.")
|
| 213 |
except Exception as e:
|
| 214 |
flash(f"Error while removing file: {str(e)}", "error")
|
| 215 |
+
print(f"Error while removing file: {str(e)}", "error")
|
| 216 |
return redirect(url_for('upload_file'))
|
| 217 |
|
| 218 |
# Route to serve uploaded files
|