sop for execuitve generator added
This commit is contained in:
+119
-2
@@ -59,7 +59,7 @@ def get_roles():
|
||||
|
||||
|
||||
|
||||
@sops_bp.route('/generate_sops', methods=['POST'])
|
||||
@sops_bp.route('/generate_sops_from_doc', methods=['POST'])
|
||||
def generate_sops():
|
||||
# Check if the POST request has the file part
|
||||
if 'document' not in request.files:
|
||||
@@ -101,7 +101,7 @@ def generate_sops():
|
||||
return jsonify({"error": "Document cannot extract SOPs", "message": status_check["message"]}), 400
|
||||
|
||||
# Generate SOPs based on the roles provided
|
||||
sops = sop_generator.generate_sops(roles, docs)
|
||||
sops = sop_generator.generate_sops_from_doc(roles, docs)
|
||||
|
||||
# Cleanup: Delete all files in the upload directory after processing
|
||||
delete_all_files_in_directory(upload_folder)
|
||||
@@ -114,3 +114,120 @@ def generate_sops():
|
||||
return jsonify({"error": "Processing error", "message": f"An error occurred while processing the document: {str(e)}"}), 500
|
||||
|
||||
return jsonify({"error": "File type not allowed", "message": "The uploaded file type is not allowed. Please upload a PDF, DOC, or DOCX file."}), 400
|
||||
|
||||
|
||||
|
||||
@sops_bp.route('/generate_sops_from_info', methods=['POST'])
|
||||
def generate_sops_from_info():
|
||||
"""
|
||||
Generate SOPs based on role information provided in the request body.
|
||||
"""
|
||||
try:
|
||||
# Get role information from the request body
|
||||
roles_info = request.json.get('roles_info')
|
||||
if not roles_info:
|
||||
return jsonify({"error": "No role information provided", "message": "Please provide role information in the 'roles_info' field."}), 400
|
||||
|
||||
# Generate SOPs based on the provided role information
|
||||
sops_response = sop_generator.generate_sops_from_info(roles=roles_info)
|
||||
|
||||
return jsonify({"sops": sops_response, "message": "SOPs successfully generated based on the provided role information."}), 200
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"error": "Processing error", "message": f"An error occurred while generating SOPs: {str(e)}"}), 500
|
||||
|
||||
|
||||
@sops_bp.route('/generate_sops_by_role_and_area', methods=['POST'])
|
||||
def generate_sops_by_role_and_area():
|
||||
try:
|
||||
# Get role and area from the request body
|
||||
role = request.json.get('role')
|
||||
area = request.json.get('area')
|
||||
|
||||
if not role or not area:
|
||||
return jsonify({"error": "Missing parameters", "message": "Both 'role' and 'area' fields are required."}), 400
|
||||
|
||||
# Generate SOPs based on the provided role and area
|
||||
sops_response = sop_generator.generate_sops_by_role_and_area(role=role, area=area)
|
||||
|
||||
return jsonify({"sops": sops_response, "message": f"SOPs successfully generated for role '{role}' in area '{area}'."}), 200
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"error": "Processing error", "message": f"An error occurred while generating SOPs: {str(e)}"}), 500
|
||||
|
||||
|
||||
|
||||
@sops_bp.route('/executive/generate_sops_from_questionnaire', methods=['POST'])
|
||||
def generate_executive_sops_from_questionnaire():
|
||||
try:
|
||||
# Get data from the request body
|
||||
data = request.json
|
||||
|
||||
# Generate SOPs based on the questionnaire answers
|
||||
sops_response = sop_generator.generate_executive_sops_from_questionnaire(data)
|
||||
|
||||
return jsonify({"sops": sops_response, "message": "SOPs successfully generated from the questionnaire."}), 200
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"error": "Processing error", "message": f"An error occurred while generating SOPs: {str(e)}"}), 500
|
||||
|
||||
|
||||
|
||||
|
||||
@sops_bp.route('/executive/generate_sops_from_doc', methods=['POST'])
|
||||
def generate_executive_sops_from_doc():
|
||||
"""
|
||||
Generate SOPs for executives based on a document containing vision and mission.
|
||||
"""
|
||||
# Check if the POST request has the file part
|
||||
if 'document' not in request.files:
|
||||
return jsonify({"error": "No file part", "message": "Please upload a file with the key 'document'."}), 400
|
||||
|
||||
file = request.files['document']
|
||||
|
||||
# If the user does not select a file, the browser may also submit an empty part without filename
|
||||
if file.filename == '':
|
||||
return jsonify({"error": "No selected file", "message": "A file was not selected for upload. Please select a valid file."}), 400
|
||||
|
||||
if file and allowed_file(file.filename):
|
||||
filename = secure_filename(file.filename)
|
||||
upload_folder = current_app.config['UPLOAD_FOLDER']
|
||||
file_path = os.path.join(upload_folder, filename)
|
||||
|
||||
# Save the file to the upload folder
|
||||
file.save(file_path)
|
||||
|
||||
try:
|
||||
# Use the utility function to generate docs from the file
|
||||
docs = load_document(file_path)
|
||||
|
||||
|
||||
# Use LLM to extract Vision and Mission sections from the document
|
||||
vision_section, mission_section = sop_generator.extract_vision_and_mission(docs)
|
||||
|
||||
if not vision_section or not mission_section:
|
||||
# Cleanup: Delete all files in the upload directory if parsing fails
|
||||
delete_all_files_in_directory(upload_folder)
|
||||
return jsonify({"error": "Missing Vision and Mission", "message": "The document does not contain or properly define the company's vision and mission."}), 400
|
||||
|
||||
# Organize extracted data
|
||||
extracted_data = {
|
||||
"role": "Executive",
|
||||
"organization vision": [vision_section],
|
||||
"organization strategic goals": [mission_section]
|
||||
}
|
||||
|
||||
# Generate SOPs based on the extracted vision and goals
|
||||
sops_response = sop_generator.generate_executive_sops_from_questionnaire(extracted_data)
|
||||
|
||||
# Cleanup: Delete all files in the upload directory after processing
|
||||
delete_all_files_in_directory(upload_folder)
|
||||
|
||||
return jsonify({"sops": sops_response, "message": "SOPs successfully generated from the document."}), 200
|
||||
|
||||
except Exception as e:
|
||||
# Cleanup: Delete all files in the upload directory if an error occurs
|
||||
delete_all_files_in_directory(upload_folder)
|
||||
return jsonify({"error": "Processing error", "message": f"An error occurred while processing the document: {str(e)}"}), 500
|
||||
|
||||
return jsonify({"error": "File type not allowed", "message": "The uploaded file type is not allowed. Please upload a PDF, DOC, or DOCX file."}), 400
|
||||
|
||||
Reference in New Issue
Block a user