Can we use the gini index to assign a class to a leaf node? If yes how? As far as I understand the gini index can only be used as a splitting metric.
Short answer: No
What do you mean by 'assign a class to a leaf node'? The question itself is strange. Gini index is used as splitting criteria in the building process of decision tree and the classes in leaf nodes are the final result of a building process.
The building of a decision tree is an automatic process based on the principle of greedy maximization of some quality criteria/splitting rule (Gini uncertainty (Gini impurity/Gini index), information gain, Misclassification error): at each step, the algorithm chooses the variable that gives the greatest value upon splitting. Then the procedure is repeated recursively until the entropy is zero (or some small value to account for overfitting).
Maximizing the Gini uncertainty can be interpreted as the maximization of the number of pairs of objects of the same class that are in the same subtree.
I will leave an example of tree below.
Also, if you want, you can check out this wonderful notebook on the theme that gives a full understanding of decision trees and the theory behind them: