AADalhat commited on
Commit
0f78d9c
·
verified ·
1 Parent(s): cff6aaa

Upload 6 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ mobilenet_model.h5.keras filter=lfs diff=lfs merge=lfs -text
HealthFood pro.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
food_info.json ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "Tuwo Shinkafa": {
3
+ "ingredients": [
4
+ "rice flour",
5
+ "water",
6
+ "salt",
7
+ "okra soup",
8
+ "meat"
9
+ ],
10
+ "calories": 350,
11
+ "risks": {
12
+ "diabetes": "high",
13
+ "hypertension": "medium",
14
+ "weight_loss": "medium"
15
+ },
16
+ "advice": "Use millet flour instead of white rice flour, reduce meat fat.",
17
+ "substitute": "Tuwo masara with ugu soup",
18
+ "diet_type": "non-vegan"
19
+ },
20
+ "Yam Porridge": {
21
+ "ingredients": [
22
+ "yam",
23
+ "palm oil",
24
+ "pepper",
25
+ "onion",
26
+ "leafy greens"
27
+ ],
28
+ "calories": 400,
29
+ "risks": {
30
+ "diabetes": "medium",
31
+ "hypertension": "high",
32
+ "weight_loss": "high"
33
+ },
34
+ "advice": "Use less palm oil, add more greens.",
35
+ "substitute": "Boiled yam with vegetable sauce",
36
+ "diet_type": "vegan"
37
+ },
38
+ "Jollof Rice": {
39
+ "ingredients": [
40
+ "white rice",
41
+ "tomato",
42
+ "pepper",
43
+ "oil",
44
+ "salt"
45
+ ],
46
+ "calories": 420,
47
+ "risks": {
48
+ "diabetes": "high",
49
+ "hypertension": "high",
50
+ "weight_loss": "high"
51
+ },
52
+ "advice": "Use brown rice, reduce oil and salt.",
53
+ "substitute": "Ofada rice with vegetable stew",
54
+ "diet_type": "non-vegan"
55
+ },
56
+ "Moi Moi": {
57
+ "ingredients": [
58
+ "beans",
59
+ "oil",
60
+ "pepper",
61
+ "onion",
62
+ "egg"
63
+ ],
64
+ "calories": 280,
65
+ "risks": {
66
+ "diabetes": "low",
67
+ "hypertension": "medium",
68
+ "weight_loss": "medium"
69
+ },
70
+ "advice": "Steam instead of baking with oil, reduce egg if needed.",
71
+ "substitute": "Boiled beans with vegetables",
72
+ "diet_type": "vegan"
73
+ },
74
+ "Suya": {
75
+ "ingredients": [
76
+ "beef",
77
+ "oil",
78
+ "pepper",
79
+ "spices",
80
+ "salt"
81
+ ],
82
+ "calories": 450,
83
+ "risks": {
84
+ "diabetes": "medium",
85
+ "hypertension": "high",
86
+ "weight_loss": "high"
87
+ },
88
+ "advice": "Limit portion size, avoid adding extra salt.",
89
+ "substitute": "Grilled chicken with pepper sauce",
90
+ "diet_type": "non-vegan"
91
+ },
92
+ "Egusi Soup": {
93
+ "ingredients": [
94
+ "egusi",
95
+ "palm oil",
96
+ "leafy greens",
97
+ "meat",
98
+ "seasoning"
99
+ ],
100
+ "calories": 500,
101
+ "risks": {
102
+ "diabetes": "medium",
103
+ "hypertension": "high",
104
+ "weight_loss": "high"
105
+ },
106
+ "advice": "Use less palm oil, add more vegetables, and lean meat.",
107
+ "substitute": "Vegetable soup with crayfish",
108
+ "diet_type": "non-vegan"
109
+ },
110
+ "Akara": {
111
+ "ingredients": [
112
+ "beans",
113
+ "pepper",
114
+ "onion",
115
+ "oil",
116
+ "salt"
117
+ ],
118
+ "calories": 330,
119
+ "risks": {
120
+ "diabetes": "medium",
121
+ "hypertension": "medium",
122
+ "weight_loss": "high"
123
+ },
124
+ "advice": "Fry with less oil or bake, avoid excess salt.",
125
+ "substitute": "Baked bean cakes",
126
+ "diet_type": "vegan"
127
+ },
128
+ "Pap (Akamu)": {
129
+ "ingredients": [
130
+ "corn",
131
+ "water",
132
+ "milk",
133
+ "sugar"
134
+ ],
135
+ "calories": 250,
136
+ "risks": {
137
+ "diabetes": "high",
138
+ "hypertension": "low",
139
+ "weight_loss": "low"
140
+ },
141
+ "advice": "Reduce sugar and use skimmed milk.",
142
+ "substitute": "Unsweetened pap with soya milk",
143
+ "diet_type": "vegan"
144
+ },
145
+ "Eba and Egusi": {
146
+ "ingredients": [
147
+ "garri",
148
+ "egusi",
149
+ "palm oil",
150
+ "meat",
151
+ "vegetables"
152
+ ],
153
+ "calories": 600,
154
+ "risks": {
155
+ "diabetes": "high",
156
+ "hypertension": "high",
157
+ "weight_loss": "high"
158
+ },
159
+ "advice": "Reduce portion, use more vegetables, and less oil.",
160
+ "substitute": "Wheat swallow with okra soup",
161
+ "diet_type": "non-vegan"
162
+ },
163
+ "Okra Soup": {
164
+ "ingredients": [
165
+ "okra",
166
+ "oil",
167
+ "pepper",
168
+ "leafy greens",
169
+ "meat"
170
+ ],
171
+ "calories": 300,
172
+ "risks": {
173
+ "diabetes": "low",
174
+ "hypertension": "medium",
175
+ "weight_loss": "low"
176
+ },
177
+ "advice": "Use little oil and lean meat, add ugu.",
178
+ "substitute": "Steamed okra with fish",
179
+ "diet_type": "non-vegan"
180
+ }
181
+ }
gradio_app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import tensorflow as tf
4
+ import numpy as np
5
+ from PIL import Image
6
+ import json
7
+ from gtts import gTTS
8
+ import os
9
+ import tempfile
10
+ from health_logic import generate_advice
11
+
12
+ # Load model
13
+ model = tf.keras.models.load_model("mobilenet_model_finetuned.h5")
14
+
15
+ # Load metadata
16
+ with open("food_info.json", "r") as f:
17
+ food_info = json.load(f)
18
+ class_names = list(food_info.keys())
19
+
20
+ def classify_food(image, conditions, language):
21
+ image = image.convert("RGB").resize((224, 224))
22
+ img_array = tf.keras.preprocessing.image.img_to_array(image) / 255.0
23
+ img_array = np.expand_dims(img_array, axis=0)
24
+
25
+ predictions = model.predict(img_array)
26
+ predicted_index = np.argmax(predictions)
27
+ predicted_class = class_names[predicted_index]
28
+ info = food_info[predicted_class]
29
+
30
+ advice, risk_score, flags = generate_advice(info, conditions)
31
+
32
+ # Construct text output
33
+ result = f"🍽️ Food: {predicted_class}\n"
34
+ result += f"📊 Risk Score: {risk_score}%\n"
35
+ result += f"⚠️ Risk Factors: {', '.join(flags) if flags else 'None'}\n"
36
+ result += f"✅ Advice: {advice}\n"
37
+ result += f"🌱 Substitute: {info.get('substitute', 'None')}\n"
38
+
39
+ # TTS
40
+ tts = gTTS(text=advice, lang=language.lower()[:2])
41
+ tmp_path = os.path.join(tempfile.gettempdir(), "tts.mp3")
42
+ tts.save(tmp_path)
43
+
44
+ return result, tmp_path
45
+
46
+ interface = gr.Interface(
47
+ fn=classify_food,
48
+ inputs=[
49
+ gr.Image(type="pil", label="Upload Food Image"),
50
+ gr.CheckboxGroup(
51
+ label="Select Health Conditions",
52
+ choices=["Normal", "Diabetic", "Hypertensive", "Weight Loss", "Malnourished", "Pregnant/Nursing", "Cholesterol Watch"]
53
+ ),
54
+ gr.Dropdown(label="Language for TTS", choices=["English", "Hausa", "Yoruba", "Igbo"], value="English")
55
+ ],
56
+ outputs=[
57
+ gr.Textbox(label="Result"),
58
+ gr.Audio(label="Hear Advice")
59
+ ],
60
+ title="🍲 HoodHealth Pro+",
61
+ description="Upload food image. Get nutrition, risk score & health advice with voice in your language."
62
+ )
63
+
64
+ if __name__ == "__main__":
65
+ interface.launch()
health_logic.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ def generate_advice(food_data, conditions):
3
+ ingredients = [i.lower() for i in food_data.get("ingredients", [])]
4
+ risk_score = 0
5
+ advice_list = []
6
+ flags = []
7
+
8
+ for condition in conditions:
9
+ if condition == "Diabetic":
10
+ if "sugar" in ingredients or food_data["carbs"] > 40:
11
+ risk_score += 25
12
+ flags.append("High carbs/sugar")
13
+ advice_list.append("Reduce starchy content, avoid sugary drinks.")
14
+ if condition == "Hypertensive":
15
+ if "salt" in ingredients or food_data["fat"] > 25:
16
+ risk_score += 20
17
+ flags.append("High salt/fat")
18
+ advice_list.append("Use less salt and oil, consider boiling or steaming.")
19
+ if condition == "Weight Loss":
20
+ if food_data["calories"] > 350:
21
+ risk_score += 15
22
+ flags.append("High calories")
23
+ advice_list.append("Reduce portion size, avoid fried foods.")
24
+ if condition == "Malnourished":
25
+ if food_data["protein"] < 10:
26
+ risk_score += 10
27
+ flags.append("Low protein")
28
+ advice_list.append("Add beans, eggs, or fish to meals for better nutrition.")
29
+ if condition == "Pregnant/Nursing":
30
+ if food_data["iron"] < 10:
31
+ risk_score += 15
32
+ flags.append("Low iron")
33
+ advice_list.append("Add leafy greens, beans, or iron supplements.")
34
+ if condition == "Cholesterol Watch":
35
+ if "palm oil" in ingredients or food_data["fat"] > 25:
36
+ risk_score += 20
37
+ flags.append("Saturated fat")
38
+ advice_list.append("Reduce palm oil and fried food intake.")
39
+ if condition == "Normal":
40
+ advice_list.append("Maintain a balanced diet with local ingredients.")
41
+
42
+ risk_score = min(risk_score, 100)
43
+ final_advice = " ".join(set(advice_list))
44
+ return final_advice, risk_score, flags
mobilenet_model.h5.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65ed628417a0ab197788f64df99aa9231256c6304b288e9a3aed858775c60195
3
+ size 9768203
requirements.txt.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ tensorflow
2
+ gradio
3
+ gtts
4
+ Pillow
5
+ numpy