What percentage of the code should be yours in a final year computer science project? I have a final year project in Artificial intelligence and I need to make a facial recognition project. I'm confused how to start this project and how plagiarism works in terms of coding? No one would make a project from scratch but the thing is my coding ability in python is very limited and the code that I have seen for facial recognition using the K nearest algorithm is like 70 lines. If I change that code with my variable names and create functions and add that code into those functions would that be a problem ? what do I do ?  I would obviously cite where I got this code from and say that my code is inspired from this. But if i just change the variables and make a few functions and add their code clearly I have done very little work in terms of coding aspect.
If I change that code with my variable names and create functions and add that code into those functions would that be a problem ?

That seems like blatant plagiarism: Taking code and changing variable names surely only serves plagiarism. Creating new functions from existing code surely only serves plagiarism too.

what do I do ?

Use as much external code as you like. That code should appear as-is, with any ownership, copyright, and licensing information intacted, where ownership information is missing, perhaps add it, at the very least, document the fact that code isn't yours.
Write your own code that uses external code. That's your contribution.
Occasionally, you may use an external code snippet within your code. Mark such code with comments, e.g., /** BEGIN: Code from xyz **/ and /** END **/.
Ultimately, your goal should be to achieve your objective with minimal code.