this code should process the user text or file it used to work successfully till I had an error and during the error I reloaded the web and it started to display this message (No recommendations to display) even though I fixed the error it still the same whenever I reloaded the web and it no more displays the boxes only the message no matter what
here is the fe code ,, I get the only message on terminal saying (INFO:root:GET request processed)
app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
text_data = request.form.get('text')
file = request.files.get('file')
response_data = {}
error_message = None
if text_data:
logging.info('Processing text data')
response_json = send_to_other_app({'text': text_data}, 'create_cv')
if response_json is not None:
recommendations = response_json['recommendations']
recommendations_newlines = recommendations.replace("['", " ").replace("',", " ").replace("']", " ").replace("'", " ")
recommendations_newlines = recommendations.replace("\n", "n")
response_json['recommendations'] = recommendations_newlines
response_data['text_response'] = response_json
logging.info(f'response_json_0 : {response_json}')
else:
error_message = 'Failed to process text data due to an external service error.'
elif file and allowed_file(file.filename):
filename = secure_filename(file.filename)
save_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(save_path)
logging.info(f'File uploaded: {filename} to path: {save_path}')
response_json = send_to_other_app({'file_path': save_path}, 'recommend')
if response_json is not None:
response_data['file_response'] = response_json
logging.info(f'response_json_1 {response_json}')
else:
logging.info(f'response_json_2 {response_json}')
error_message = 'Failed to process file due to an external service error.'
if response_data:
logging.info(f"Response data available: {response_data}")
return render_template('recommendations.html', response=response_data)
if not response_data and not error_message:
logging.info("No response data available.")
error_message = 'No text data or valid file provided for processing.'
logging.error(error_message)
return jsonify({'error': error_message}), 400
# Handle GET request
logging.info('GET request processed')
return render_template('index.html')
here is the html code
</style>
</head>
<body>
<div class="container">
{% if response %}
{% if response.text_response %}
<!-- CV Generated Box -->
<div class="box">
<h2>CV Generated</h2>
<div class="content-box">
<pre>{{ response.text_response.created_cv }}</pre>
</div>
</div>
<!-- Recommendations Box -->
<div class="box">
<h2>Recommendation</h2>
<div class="content-box">
<!-- Convert escaped newlines to HTML line breaks -->
<pre>{{ response.text_response.recommendations}}</pre>
</div>
</div>
{% endif %}
{% if response.file_response %}
<!-- File Response Box -->
<div class="box">
<h2>Recommendation</h2>
<div class="content-box">
<pre>{{ response.file_response.recommendations }}</pre>
</div>
</div>
{% endif %}
{% else %}
<div class="no-recommendations">
<p>No recommendations to display at the moment.</p>
</div>
{% endif %}
</div>
</body>
</html>