So, let's see if I get this right.
You are employed by this company. Independently, you also have another contract on top of that for work to do in your own time in exchange for additional remuneration, with extra penalties if you leave. You signed this contract fully understanding the implications.
No additional training or resources were promised or provided. The contract was not intended to be fore work hours, and you've been given no work hours for it.
The extra penalties of the contract were 10,000 pounds if you left before full completion. You have not yet achieved full completion.
Overall, as a result of signing the contract (and doing some non-work-hours work) you've thus far received 7,000 pounds. The early departure penalty was 10,000 pounds.
The work you've done thus far was not a trivial amount, but is not something that the company can meaningfully leverage without you continuing to work on it, and may not be of any value to them at all in your absence.
You've gotten demoralized and want to leave. The company has said that in order to leave, you need to pay back some money - not the 10,000 or even the 7,000 but just 4,100. You don't have that money, and you want to know if this is fair.
The fact is, with the contract as described, this is more than fair. This is the company being kind. The're totally within rights to charge you the full 10,000. By charging less than the 7,000 they're actually taking a loss on your little side-contract thing - they paid you more than that on the expectation that you would deliver something of value, and you haven't delivered anything they can use yet. The fact that you don't have that kind of money is not their fault... especially with the additional money that you've gotten from them already.
Yes. They can probably take you to court over this, or equivalent. Based on the contract as described, there's a good chance they could get more out of you than just the 4,100 if they wanted (quite possibly making you pay the attorney's fees as well). That's the thing about lock-in contracts. They lock you in. It's possible that you could slip out of this one on a technicality, and talking with a lawyer would help you find one, but lawyer time isn't free.
Your best option at this point, if you can manage it, is to adjust your expectations, make your peace with your situation, somehow manage your emotional state, and finish out the contract. Admittedly, managing your own mental state to that degree is not easy. Still, it's possible that if you have specific issues with the way they've been treating you recently, you could ask here, and we could provide suggestions on what to do to make the situation more livable while staying employed, finishing the portfolio side contract, and so forth. You did think it was a good deal at one point, after all. There has to be some upside... and it sounds like the sort of thing that would be really good for your career overall, if you can manage it. Take it as a challenge, rather than a misery.
If that is not possible for you for whatever reason (entirely understandable), then you're going to want to wander over to money.stackexchange.com (and perhaps a few frugality blogs), because it's time for some serious belt-tightening. You don't have the 4,100 pounds now, but I can almost guarantee that you can save it up within the six months if you're willing to budget hard enough. It would probably be good for you, honestly.
Whatever you do, don't try to fight them on the 4,100 pounds without spending some serious time talking with a lawyer you can trust. It could get a lot worse.