Fantastic enquiry , you've researched well. Both are great bikes from established manufacturers, the question is can you justify the 20% premium for the trek?
If it was me, I'd be trying to justify the trek - especially if I was carrying extra weight / loads / higher speeds.
Little things, but the solid axle on the front wheel will make for more precise steering than a QR , and give you MUCH better options down the track if you decide to upgrade forks ( all the high quality forks use through axle) , the 4 pot shimano 520 brakes offer fantastic feel , slightly more power, and MUCH better pad life ( larger pads) .
Admittedly I despise the alex rims on that trek - so if you intend to run tubeless in the future be prepared for a difficult conversion ( not impossible, but you have to be extremely careful with the tape) . I do prefer the trek hubs compared with giant - they're easier to maintain / service ( again, just shed time or needing a more skilled mechanic at the lbs)
Trek has arguably better build quality than giant - probably not an issue on these bikes but they put a bit more thought into frame design - eg if you look at the rear axle / chainstays the trek has the welds / weak po8nts/ further apart / a n a lower stress area ( more difficult to manufacture but one less failure point) . It's highly unlikely that a normal person will brake either of these frames, but I find it reassuring to see that level of thought. Eg On their dual suspension mountain bikes they have bushes at the linkages rather than just alloy on alloy 4 years later this can result in some flex on a giant ( at least my extremely abused giant)
Both bosch and giant ( yamaha) are reasonably reliable motors, but be aware giant warranty is not a rolling warranty like yamaha offers on yamaha bikes - ie if the motor is replaced on the last day of warranty, you don't get an extra 2 years. Giant warranty is not transferable to new owners - so if you decide to upgrade there will be no warranty for the next buyer. You'll have to ask about trek, but know
specialized warranty IS transferable ( and a rolling warranty on the motor)
I THINK trek warranty covers consumables like bearings - giant doesn't ( I had wheel bearings fail within 3 weeks on my giant ! )
I think giant parts are generally cheaper to replace than trek, so eg if the battery dies out of warranty it's generally cheaper for giant.