Views
No views yet
1from huggingface_hub import hf_hub_download
2import tensorflow as tf
3import joblib
4import numpy as np
5
6# Download model
7model = tf.keras.models.load_model(
8 hf_hub_download(repo_id="developerPratik/vitamind-calorie-predictor", filename="model.keras")
9)
10scaler = joblib.load(
11 hf_hub_download(repo_id="developerPratik/vitamind-calorie-predictor", filename="scaler.joblib")
12)
13encoders = joblib.load(
14 hf_hub_download(repo_id="developerPratik/vitamind-calorie-predictor", filename="encoders.joblib")
15)
16
17# Example prediction
18user_data = {
19 'age': 30, 'weight': 75, 'height': 175, 'steps': 8000,
20 'heart_rate': 72, 'sleep_hours': 7.5, 'stress_level': 4,
21 'activity_level': 'Active', 'gender': 'M', 'mood': 'happy'
22}
23
24# Feature engineering
25bmi = user_data['weight'] / ((user_data['height'] / 100) ** 2)
26good_sleep = 1 if user_data['sleep_hours'] >= 7 else 0
27high_stress = 1 if user_data['stress_level'] >= 7 else 0
28activity_scores = {'Sedentary': 1, 'Lightly Active': 2, 'Active': 3, 'Very Active': 4, 'Athlete': 5}
29
30# Encode
31activity_encoded = encoders['activity_level'].transform([user_data['activity_level']])[0]
32gender_encoded = encoders['gender'].transform([user_data['gender']])[0]
33mood_encoded = encoders['mood'].transform([user_data['mood']])[0]
34
35# Create feature vector (14 features)
36features = np.array([[
37 user_data['age'], user_data['weight'], user_data['height'],
38 user_data['steps'], user_data['heart_rate'], user_data['sleep_hours'],
39 user_data['stress_level'], bmi, activity_encoded, gender_encoded,
40 mood_encoded, good_sleep, high_stress, activity_scores[user_data['activity_level']]
41]])
42
43# Predict
44features_scaled = scaler.transform(features)
45calories = model.predict(features_scaled, verbose=0)[0][0]
46print(f"Recommended daily calories: {calories:.0f} kcal")Input (14 features)
↓
Dense(256) + BatchNorm + Dropout(0.3)
↓
Dense(128) + BatchNorm + Dropout(0.3) [Residual Connection]
↓
Dense(128) + BatchNorm + Dropout(0.3)
↓
Dense(64) + BatchNorm + Dropout(0.2)
↓
Output (1 - calories)| Feature | Type | Description |
|---|---|---|
| age | int | Age in years (18-100) |
| weight | float | Weight in kg (40-150) |
| height | float | Height in cm (140-220) |
| steps | int | Daily steps (0-30000) |
| heart_rate | int | Resting heart rate (50-120) |
| sleep_hours | float | Hours of sleep (3-12) |
| stress_level | int | Stress rating (1-10) |
| bmi | float | Calculated BMI |
| activity_level | str | Sedentary/Lightly Active/Active/Very Active/Athlete |
| gender | str | M/F |
| mood | str | happy/neutral/sad/anxious |
| good_sleep | binary | 1 if sleep >= 7 hours |
| high_stress | binary | 1 if stress >= 7 |
| activity_score | int | 1-5 based on activity level |
1@software{vitamind_ai_2025,
2 author = {{Your Name}},
3 title = {{VitaMind AI Calorie Predictor}},
4 year = {2025},
5 publisher = {Hugging Face},
6 url = {{https://huggingface.co/developerPratik/vitamind-calorie-predictor}}
7}