This is my code

```

from flask import Flask, request, jsonify, send_file
import os
from flask_cors import CORS
from werkzeug.utils import secure_filename
from langchain_openai import ChatOpenAI
from langchain.schema.messages import AIMessage
from langchain.prompts import PromptTemplate
from langchain_core.runnables.base import RunnableSequence
from utils import process_file_with_instructions
from dotenv import load_dotenv
import docx 
from io import BytesIO
from datetime import datetime

load_dotenv()
 
app = Flask(__name__)
CORS(app)
 
app.config['UPLOAD_FOLDER'] = './uploads'
app.secret_key = 'supersecretkey'
 
if not os.path.exists(app.config['UPLOAD_FOLDER']):
    os.makedirs(app.config['UPLOAD_FOLDER'])
 
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
if not OPENAI_API_KEY:
    raise ValueError("Please set the OPENAI_API_KEY environment variable.")
 
llm = ChatOpenAI(api_key=OPENAI_API_KEY, model_name="gpt-4o-mini")
 
prompt_template = PromptTemplate(
    input_variables=["document", "instructions"],
    template="""
    Document: {document}
 
    Instructions: {instructions}
 
    Based on the document and instructions provided, generate the required content.  And you are not allowed to have any special characters in the output.
    """
)
 
chain = RunnableSequence(
    prompt_template,
    llm
)
 
# Temporary storage to hold filename and instructions
upload_data = {}
 
# Route 1: Upload the file and return the filename
@app.route('/autodraft/file', methods=['POST'])
def upload_file():
    if 'file' not in request.files:
        return jsonify({"error": "No file part in the request"}), 400
   
    file = request.files['file']
   
    if file.filename == '':
        return jsonify({"error": "No selected file"}), 400
   
    if file:
        filename = secure_filename(file.filename)
        filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
        file.save(filepath)
       
        # Store filename in upload_data (temporary store)
        upload_data['filename'] = filename
       
        return jsonify({"message": f"File {filename} uploaded successfully", "filename": filename}), 200
 
# Route 2: Submit instructions (with filename)
@app.route('/autodraft/instructions', methods=['POST'])
def add_instructions():
    data = request.json
    instructions = data.get("instructions")
    filename = upload_data.get('filename')  # Retrieve from temporary store
   
    if not filename:
        return jsonify({"error": "Filename is missing."}), 400
   
    if not instructions:
        return jsonify({'error': "Instructions are required."}), 400
   
    # Store instructions along with the filename
    upload_data['instructions'] = instructions
   
    return jsonify({
        "message": "Instructions submitted successfully",
        "filename": filename,
        "instructions": instructions,
    }), 200
 
# Route 3: Review the document using filename and instructions (GET)
@app.route('/autodraft/review', methods=['GET'])
def review_document():
    filename = upload_data.get('filename')  # Retrieve from temporary store
    instructions = upload_data.get('instructions')  # Retrieve from temporary store
   
    if not filename or not instructions:
        return jsonify({"error": "Filename or instructions missing."}), 400
   
    filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
   
    processed_content = process_file_with_instructions(filepath, instructions, chain)
   
    if isinstance(processed_content, AIMessage):
        processed_content = processed_content.content
    upload_data['processed_content'] = processed_content
    return jsonify({"processed_content": processed_content}), 200
 
@app.route('/download', methods=["GET"])
def download_file():
    processed_content = upload_data.get('processed_content')

    if not processed_content:
        return jsonify({"error": "No processed content available for download"}), 400

    # Create a Word document in memory
    doc = docx.Document()
    
    # Split the processed content into lines based on newline characters
    content_lines = processed_content.split('\n')
    
    for line in content_lines:
        if line.strip():  # Ensure the line is not empty
            doc.add_paragraph(line.strip())

    doc_io = BytesIO()
    doc.save(doc_io)
    doc_io.seek(0)
    timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
    doc_filename = f"output_{timestamp}.docx"

    return send_file(
        doc_io,
        mimetype='application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        as_attachment=True,
        download_name=doc_filename
    )


if __name__ == '__main__':
    app.run(host="0.0.0.0", port=5000, debug=True)
 ```

I want you to handle this code forany errors. for example: In the first API the user should be able to upload only one file and should of docx format.