To solve this optimization problem, we first need to define the decision variables and the objective function. Let's denote the number of cans of Soda 1 to be purchased as \(x_1\) and the number of cans of Soda 2 to be purchased as \(x_2\). The objective is to minimize the total cost, which can be represented as \(5x_1 + 7x_2\), given that each can of Soda 1 costs $5 and each can of Soda 2 costs $7.

The constraints are:
1. **Caffeine Constraint**: We must consume at least 50 units of caffeine. Given that Soda 1 contains 3 units of caffeine per can and Soda 2 contains 2 units of caffeine per can, this constraint can be represented as \(3x_1 + 2x_2 \geq 50\).
2. **Sugar Constraint**: We must consume at least 40 units of sugar. Given that Soda 1 contains 2 units of sugar per can and Soda 2 contains 5 units of sugar per can, this constraint can be represented as \(2x_1 + 5x_2 \geq 40\).
3. **Non-Negativity Constraints**: Since we cannot buy a negative number of cans, both \(x_1\) and \(x_2\) must be non-negative, which is represented as \(x_1 \geq 0\) and \(x_2 \geq 0\).

Now, let's translate this problem into Gurobi code in Python:

```python
from gurobipy import *

# Create a new model
m = Model("Soda_Optimization")

# Define the decision variables
x1 = m.addVar(vtype=GRB.CONTINUOUS, name="Soda_1", lb=0)
x2 = m.addVar(vtype=GRB.CONTINUOUS, name="Soda_2", lb=0)

# Set the objective function: Minimize total cost
m.setObjective(5*x1 + 7*x2, GRB.MINIMIZE)

# Add constraints
m.addConstr(3*x1 + 2*x2 >= 50, "Caffeine_Constraint")
m.addConstr(2*x1 + 5*x2 >= 40, "Sugar_Constraint")

# Optimize the model
m.optimize()

# Print the results
if m.status == GRB.OPTIMAL:
    print("Optimal solution found:")
    print(f"Buy {x1.x} cans of Soda 1")
    print(f"Buy {x2.x} cans of Soda 2")
    print(f"Total cost: ${m.objVal}")
else:
    print("No optimal solution found")
```