Commit 1dcc4b64 authored by Sasini Perera's avatar Sasini Perera

Merge branch 'master' of http://gitlab.sliit.lk/tmp-23-068/tmp-23-068 into suggestions_chatbot

parents a128f39e 1713a20b
/*import React, { useState } from 'react';
import { Button, Image, Text, View, TextInput, ScrollView } from 'react-native';
import * as ImagePicker from 'expo-image-picker';
import axios from 'axios';
export default function Nutrition() {
const [imageCBC, setImageCBC] = useState(null);
const [imageOGTT, setImageOGTT] = useState(null);
const [resultCBC, setResultCBC] = useState('');
const [resultOGTT, setResultOGTT] = useState('');
const [bmi, setBMI] = useState('');
const [otherModelResult, setOtherModelResult] = useState('');
const pickImage = async (reportType) => {
const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
if (status !== 'granted') {
alert('Permission to access media library is required!');
return;
}
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [4, 3],
});
if (!result.cancelled) {
if (reportType === 'CBC') {
setImageCBC(result.uri);
} else if (reportType === 'OGTT') {
setImageOGTT(result.uri);
}
const formData = new FormData();
formData.append('file', {
uri: result.uri,
type: 'image/jpeg',
name: 'image.jpg',
});
const apiUrl = reportType === 'CBC' ? 'http://192.168.43.56:5004/extract_hemoglobin' : 'http://192.168.43.56:5004/extract_glucose';
axios.post(apiUrl, formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
})
.then(response => {
if (reportType === 'CBC') {
setResultCBC(response.data.result);
} else if (reportType === 'OGTT') {
setResultOGTT(response.data.result);
}
})
.catch(error => {
console.error(error);
if (reportType === 'CBC') {
setResultCBC('Error while processing the image.');
} else if (reportType === 'OGTT') {
setResultOGTT('Error while processing the image.');
}
});
}
};
const sendToOtherModel = () => {
if (!resultCBC || !resultOGTT || !bmi) {
alert('Please provide Hemoglobin, Glucose, and BMI values.');
return;
}
console.log(parseFloat(resultCBC));
console.log(parseFloat(resultOGTT));
console.log(parseFloat(bmi));
const apiUrl = 'http://192.168.43.56:5005/predict'; // Replace with the actual API endpoint URL of the other model
axios
.post(apiUrl, {
Hemoglobin_Level: parseFloat(resultCBC),
Fasting_Glucose_Level: parseFloat(resultOGTT),
BMI_Value: parseFloat(bmi),
})
.then(response => {
// Define a mapping of output values to custom texts
const outputTexts = {
1: "Your strength and determination in managing diabetes during pregnancy are like a beacon of inspiration, guiding you and your baby towards a brighter and healthier tomorrow; Breakfast: Red rice 1- 1 1/2 cup + vegetables + meat/fish/egg or gram (Kadala) /Black EyedBeans (Kawpi) with coconut + Kola Kenda 1 cup or Dosa 1-1 ½; Morning Snak: 1 yogurt without sugar/ 1 Milk Tea without Sugar with Fruit; Lunch: Red Rice/ Niwdu 2 cups + Vegetables 7 tablespoons + meat/fish/egg; Evening Snack: 1 Milk tea without sugar with Half-ripe Fruit/1 Kurakkan Helapa/1 Hopper/1 Kurakkan Roti/1 Pancake/Peanuts 1 tablespoon/Almond; Dinner: Noodles/Pasta 2 cups/4 Thin Sliced Kurakkan Bread/Dosa 2-3; Late-night snack: 1 Milk tea without sugar with 2 cracker Biscuit; This amount can be taken when eating a half-ripe Fruit: Avocado 1/2, Watermelon 1/4, Kiwi Guava 1/2, 1 Orange, Mango (1/2 cup), Pineapple 2 slices, Nelli 10, Ceylon Olive (Weeralu) 10, Ambarella 2, Small apple 1, Grapes 5-6, Banana 3/4, Dates 2, Sultanas 1 tablespoon",
2: "Your strength and determination in managing diabetes during pregnancy are like a beacon of inspiration, guiding you and your baby towards a brighter and healthier tomorrow; Breakfast: Red rice 1- 1 1/2 cup + vegetables + meat/fish/egg or gram (Kadala) /Black EyedBeans (Kawpi) with coconut + Kola Kenda 1 cup or Dosa 1-1 ½; Morning Snak: 1 yogurt without sugar/ 1 Milk Tea without Sugar with Fruit; Lunch: Red Rice/ Niwdu 2cups + Vegetables 7 tablespoons + meat/fish/egg; Evening Snack: 1 Milk tea without sugar with Half-ripe Fruit/ 1 Kurakkan Helapa /1 Hopper / 1 Kurakkan Roti / 1 Pancake / Peanuts 1 table spoon / Almond; Dinner: Noodles /Pasta 2 cups / 4 Thin Sliced Kurakkan Bread / Dosa 2-3; Late-night snack: 1 Milk tea without sugar with 2 cracker Biscuit; This amount can be taken when eating a half-ripe Fruit: Avocado 1/2, Watermelon 1/4, Kiwi Guava 1/2, 1 Orange, Mango (1/2 cup), Pineapple 2 slices, Nelli 10, Ceylon Olive (Weeralu) 10, Ambarella 2, Small apple 1, Grapes 5-6, Banana 3/4, Dates 2, Sultanas 1 tablespoon",
3: "Your commitment to a balanced diet isn't just about numbers; it's about nurturing your well-being and your baby's health. Keep up the great work; Breakfast: Red rice 1- 1 1/2 cup + vegitables + meat/fish/egg or gram (Kadala) /Black EyedBeans (Kawpi) with coconut + Kola Kenda 1 cup or Dosa 1-1 1/2; Morning Snak: 1 yogurt without sugar/ 1 Milk Tea without Sugar or Half-Ripe Fruit; Lunch: Red Rice/ Niwdu 1 1/2cups +Vegetables 7 tablespoons + meat/fish/egg; Evening Snack: 1 Milk Tea without Sugar or Half-ripe Fruit/ 1 Kurakkan Helapa /1 Hopper / 1 Kurakkan Roti / 1 Pancake / Peanuts 1 table spoon / Almond; Dinner: Noodles /Pasta 1 1/2 cups / 2 Thin Sliced Kurakkan Bread / Dosa 2; Late-night snack: 1 Milk tea without sugar; This amount can be taken when eating a half-ripe Fruit: Avocado 1/2, Watermelon 1/4, Kiwi Guava 1/2, 1 Orange, Mango (1/2 cup), Pineapple 2 slices, Nelli 10, Ceylon Olive (Weeralu) 10, Ambarella 2, Small apple 1, Grapes 5-6, Banana 3/4, Dates 2, Sultanas 1 tablespoon",
4: "Maintaining a healthy BMI during pregnancy reflects your dedication to a thriving journey for both you and your baby. Keep up the great work, Breakfast: Mung beans/Chick peas/Cowpeas - 1 1/2 cups Or Sweetpotato/manihot/yams, If you are wishing to take rice or string hoppers and vegetables, Rice - add 1/2 cup of rice to your normal dietery dish, String hoppers - take additional few string hoppers to your normal dietery dish, Any knid of vegetable + chicken/fish/egg/dry-fish/sprats, Morning snack: Veralu, jambu, naran like indegenous fruits, Thalakarali or yoghurt, Lunch: Rice - add 1/2 cup of rice to your normal dietery dish, Vegetables - add 1/2 cup of vegetables to your normal dietery dish, chicken/fish/egg/dry-fish/sprats, Fruits, Evening snack: Tea + small food; Dinner: Rotti/pittu/string hoppers/hoppers like small diet",
5: "Maintaining a healthy BMI during pregnancy reflects your dedication to a thriving journey for both you and your baby. Keep up the great work; Breakfast: Mung beans/Chick peas/Cowpeas - 1 1/2 cups Or Sweetpotato/manihot/yams, If you are wishing to take rice or string hoppers and vegetables, Rice - add 1/2 cup of rice to your normal dietery dish, String hoppers - take additional few string hoppers to your normal dietery dish, Any knid of vegetable + chicken/fish/egg/dry-fish/sprats; Morning snack: Veralu, jambu, naran like indegenous fruits, Thalakarali or yoghurt; Lunch: Rice - add 1/2 cup of rice to your normal dietery dish, Vegetables - add 1/2 cup of vegetables to your normal dietery dish, chicken/fish/egg/dry-fish/sprats, Fruits; Evening snack: Tea + small food; Dinner: Rotti/pittu/string hoppers/hoppers like small diet; However, avoid of eating chocolates, sugary biscuits, sugar added tea, instant and articial food. It is preferable to lower the carbohydrate and substitute nutritious meals like vegetables, leaves, soybeans, and green grams instead reducing high-sugar foods and fat. Include additional foods rich in protein. Create a dinner platter that includes two or more veggies, fruit. Eat three meals every day.",
6: "Your dedication to managing anemia while maintaining a healthy BMI is a testament to your strength and resilience. Keep nourishing your body and baby with your thoughtful choices; Breakfast: Mung beans/Chickpeas/Cowpeas - 1 1/2 cups Or Sweetpotato/manihot/yams or 1 cup of oatmeal topped with sliced strawberries and a tablespoon of chopped nuts. &1 cup of low-fat milk or a dairy-free alternative Or 2 string hoppers (idiyappam) with a 1/4 cup of coconut sambol and a boiled egg Or 1 serving of pittu with a 1/2 cup of dhal curry Or 1 cup of Greek yogurt with sliced bananas and a drizzle of honey Or Dosa with coconut chutney and a small serving of sambar. Or 1 serving of whole-grain toast with avocado spread and a boiled egg; If you are wishing to take rice or string hoppers and vegetables, Rice - additonal 1/2 cup of rice for your normal dietery dish, String hoppers - take additional few string hoppers to your normal dietery dish, Vegetable + chicken/fish/egg/dry-fish/sprats; Morning snack: Never take tea and coffee until 2 hrs of taking the main meal, Oranges/lime/naran like drinks, Carrot/beet juices, King coconut, Pomegranate, Almond seeds; Lunch: Rice - additional 1/2 cup of rice for your normal dietery dish, Vegetables - add 1/2 cup of vegetables for your normal dietery dish, Green leaves such as spinach, gotukola, A fresh salad with tomato, chicken/sall fishes/eggs/pork/red meat/liver parts, Lentils/beans, Fruits; Evening snack: Never take tea or coffee until 2 hrs of taking the main meal, Pomegrenate, dates, Oranges/lime/naran like drinks; Dinner: Rotti/pittu/string hoppers/hoppers like small diet or 2 rotis (approximately 2 fists in size) with 1/2 cup of dhal curry. &1 cup of cucumber salad or 1/2 cup of jackfruit curry. or 1/2 cup of gotu kola (pennywort) sambol or 1/2 cup of lentil curry (parippu) &1/2 cup of cucumber salad or 1/2 cup of eggplant (wambatu) moju; *Avoid of eating instant and articial food",
7: "Your determination to combat anemia during pregnancy is a testament to your strength. Each nutritious choice brings you closer to a healthier, brighter tomorrow for you and your little one; Breakfast: Mung beans/Chick peas/Cowpeas - 1 1/2 cups Or Sweetpotato/manihot/yams, If you are wishing to take rice or string hoppers and vegetables, Rice - additonal 1/2 cup of rice for your normal dietery dish, String hoppers - take additional few string hoppers to your normal dietery dish, Vegetable + chicken/fish/egg/dry-fish/sprats; Morning snack: Never take tea and coffee until 2 hrs of taking the main meal, Oranges/lime/naran like drinks, Carrot/beet juices, King coconut, Pomegranate, Almond seeds; Lunch: Rice - additional 1/2 cup of rice for your normal dietery dish, Vegetables - add 1/2 cup of vegetables for your normal dietery dish, Green leaves such as spinach, gotukola, A fresh salad with tomato , chicken/sall fishes/eggs/pork/red meat/liver parts , Lentils/beans, Fruits; Evening snack: Never take tea or coffee until 2 hrs of taking the main meal, Pomegrenate, dates, Oranges/lime/naran like drinks; Dinner: Rotti/pittu/string hoppers/hoppers like small diet; *Avoid of eating instant and articial food",
8: "Your determination to combat anemia during pregnancy is a testament to your strength. Each nutritious choice brings you closer to a healthier, brighter tomorrow for you and your little one; Breakfast: Mung beans/Chick peas/Cowpeas - 1 1/2 cups Or Sweetpotato/manihot/yams, If you are wishing to take rice or string hoppers and vegetables, Rice - additonal 1/2 cup of rice for your normal dietery dish, String hoppers - take additional few string hoppers to your normal dietery dish, Vegetable + chicken/fish/egg/dry-fish/sprats; Morning snack: Never take tea and coffee until 2 hrs of taking the main meal, Oranges/lime/naran like drinks, Carrot/beet juices, King coconut, Pomegranate, Almond seeds; Lunch: Rice - additional 1/2 cup of rice for your normal dietery dish, Vegetables - add 1/2 cup of vegetables for your normal dietery dish, Green leaves such as spinach, gotukola, A fresh salad with tomato, chicken/sall fishes/eggs/pork/red meat/liver parts, Lentils/beans, Fruits; Evening snack: Never take tea or coffee until 2 hrs of taking the main meal, Pomegrenate, dates, Oranges/lime/naran like drinks; Dinner: Rotti/pittu/string hoppers/hoppers like small diet; *Avoid of eating instant and articial food",
9: "Your commitment to a healthy diet during pregnancy is nurturing the best possible start for your baby. Keep up the great work; Eat a balanced diet. Stay hydrated. Take prenatal vitamins; What to Avoid: Raw or Undercooked Seafood: To prevent foodborne illnesses, avoid raw or undercooked fish and seafood, Excessive Spices: While spices are an integral part of Sri Lankan cuisine, avoid excessive spice levels, which can cause heartburn and digestive discomfort; Caffeine: Limit your caffeine intake, as excess caffeine can affect the developing baby, Alcohol: Completely avoid alcohol during pregnancy, Processed and Junk Food: Minimize your consumption of processed foods, sugary snacks, and fried items, High Mercury Fish: Certain fish like shark, swordfish, and king mackerel have high mercury levels, so limit your consumption of these, Unpasteurized Dairy: Avoid unpasteurized milk and dairy products as they may carry harmful bacteria.",
10: "6:00 AM: 1 Milk Tea without Sugar /1 yogurt without sugar with Fruit, Biscuits/Sweets/Short Eats; 8:00 AM: 2 cups of Rice (Niwudu Rice), 1 cup of Vegetables, ½ cup of Mallum/Green Leaves (Gotukola, fresh salad with tomato and spinach), 2 tablespoons of Varieties of lentils (Dal) / Grains (Soya Beans/Mung Beans/Chickpeas/Cowpeas/Beans/Long Beans (Ma Karal)/Winged, Egg Yolk/Red Meat/Chicken/Small Fishes/Pork/Liver Parts /Dry Fish as per your preference; 10:30 AM: Fruit Juice/Kola Kandha/Milk, Short Eats/Sweets/ Peanuts/Cashews/Dates/Sultanas; 1:00 PM: 2 cups of Rice (Niwudu Rice), 1 cup of Vegetables, ½ cup of Mallum/Green Leaves (Gotukola, fresh salad with tomato and spinach), 2 tablespoons of Varieties of lentils (Dal) / Grains (Soya Beans/Mung Beans/Chickpeas/Cowpeas/Beans/Long Beans (Ma Karal)/Winged, Egg Yolk/Red Meat/Chicken/Small Fishes/Pork/Liver Parts /Dry Fish as per your preference, Citric fruit (like orange/lime juice); 4:30 PM: Soup/Fruit Juice/Milk, Short Eats/Sweets/ Peanuts/Cashews/Dates/Sultanas; 8:00 PM: 2 cups of Rice (Niwudu Rice), 1 cup of Vegetables, ½ cup of Mallum/Green Leaves (Gotukola, fresh salad with tomato and spinach), 2 tablespoons of Varieties of lentils (Dal) / Grains (Soya Beans/Mung Beans/Chickpeas/Cowpeas/Beans/Long Beans (Ma Karal)/Winged, Egg Yolk/Red Meat/Chicken/Small Fishes/Pork/Liver Parts /Dry Fish as per your preference, Citric fruit (like orange/lime juice); Late-night snack: 1 Milk tea without sugar with 2 cracker Biscuit, 1 Rice Cup = 5 String Hoppers/1 Roti/1 cup Noodles/¾ cup Grains/¾ cup Milk Rice; *Please avoid consuming instant foods and limit your intake of sugary foods and heavily fried or excessively oily dishes.",
11: "6:00 AM: 1 Milk Tea without Sugar /1 yogurt without sugar with Fruit; 8:00 AM: 2 cups of Rice (Niwudu Rice), 1 cup of Vegetables, ½ cup of Mallum/Green Leaves (Gotukola, fresh salad with tomato and spinach), 2 tablespoons of Varieties of lentils (Dal) / Grains (Soya Beans/Mung Beans/Chickpeas/Cowpeas/Beans/Long Beans (Ma Karal)/Winged, Egg Yolk/Red Meat/Chicken/Small Fishes/Pork/Liver Parts /Dry Fish as per your preference; 10:30 AM: 1 Milk tea without sugar with Half-ripe Fruit/ 1 Kurakkan Helapa /1 Hopper / 1 Kurakkan Roti / 1 Pancake / Peanuts 1 table spoon / Almond/ Peanuts/Cashews/Dates/Sultanas/ Kola Kandha; 1:00 PM: 2 cups of Rice (Niwudu Rice), 1 cup of Vegetables, ½ cup of Mallum/Green Leaves (Gotukola, fresh salad with tomato and spinach), 2 tablespoons of Varieties of lentils (Dal) / Grains (Soya Beans/Mung Beans/Chickpeas/Cowpeas/Beans/Long Beans (Ma Karal)/Winged, Egg Yolk/Red Meat/Chicken/Small Fishes/Pork/Liver Parts /Dry Fish as per your preference, Citric fruit (like orange/lime juice) / Sweets; 4:30 PM: 1 Milk tea without sugar with Half-ripe Fruit/ Soup /1 Kurakkan Helapa /1 Hopper / 1 Kurakkan Roti / 1 Pancake / Peanuts 1 table spoon / Almond/ Peanuts/Cashews/Dates/Sultanas; 8:00 PM: 2 cups of Rice (Niwudu Rice), 1 cup of Vegetables, ½ cup of Mallum/Green Leaves (Gotukola, fresh salad with tomato and spinach), 2 tablespoons of Varieties of lentils (Dal) / Grains (Soya Beans/Mung Beans/Chickpeas/Cowpeas/Beans/Long Beans (Ma Karal)/Winged, Egg Yolk/Red Meat/Chicken/Small Fishes/Pork/Liver Parts /Dry Fish as per your preference, Citric fruit (like orange/lime juice)) or sweet; Late-night snack: 1 Milk tea without sugar with 2 cracker Biscuit, 1 Rice Cup = 5 String Hoppers/1 Roti/1 cup Noodles/¾ cup Grains/¾ cup Milk Rice; *Please avoid consuming instant foods and limit your intake of sugary foods and heavily fried or excessively oily dishes.",
12: "6:00 AM: 1 yogurt without sugar/ 1 nonfat Milk Tea without Sugar /Half-Ripe Fruit; 8:00 AM: 1 1/2 cups of Rice (Niwudu Rice), 1 cup of Vegetables, ½ cup of Mallum/Green Leaves (Gotukola, fresh salad with tomato and spinach), 2 tablespoons of Varieties of lentils (Dal) / Grains (Soya Beans/Mung Beans/Chickpeas/Cowpeas/Beans/Long Beans (Ma Karal)/Winged, Egg Yolk/Red Meat/Chicken/Small Fishes/Pork/Liver Parts /Dry Fish as per your preference; 10:30 AM: 1 Nonfat Milk Tea without Sugar/Fruit Juice without sugar Yogurt without sugar /Vegetable Salad/Half Ripe Fruits or Half-ripe Fruit/ 1 Kurakkan Helapa /1 Hopper / 1 Kurakkan Roti / 1 Pancake / Peanuts 1 table spoon / Almond/ Peanuts/Cashews/Dates/Sultanas; 1:00 PM: 1 cups of Rice (Niwudu Rice), 1 cup of Vegetables, ½ cup of Mallum/Green Leaves (Gotukola, fresh salad with tomato and spinach), 2 tablespoons of Varieties of lentils (Dal) / Grains (Soya Beans/Mung Beans/Chickpeas/Cowpeas/Beans/Long Beans (Ma Karal)/Winged, Egg Yolk/Red Meat/Chicken/Small Fishes/Pork/Liver Parts /Dry Fish as per your preference, Citric fruit (like orange/lime juice); 4:30 PM: 1 Nonfat Milk Tea without Sugar/Fruit Juice without sugar Yogurt without sugar /Vegetable Salad/Half Ripe Fruit or Half-ripe Fruit/ 1 Kurakkan Helapa /1 Hopper / 1 Kurakkan Roti / 1 Pancake / Peanuts 1 table spoon / Almond/ Peanuts/Cashews/Dates/Sultanas; 8:00 PM: 1/2 cups of Rice (Niwudu Rice), 1 cup of Vegetables, ½ cup of Mallum/Green Leaves (Gotukola, fresh salad with tomato and spinach), 2 tablespoons of Varieties of lentils (Dal) / Grains (Soya Beans/Mung Beans/Chickpeas/Cowpeas/Beans/Long Beans (Ma Karal)/Winged, Egg Yolk/Red Meat/Chicken/Small Fishes/Pork/Liver Parts /Dry Fish as per your preference, Citric fruit (like orange/lime juice); Late-night snack: 1 Milk tea without sugar, 1 Rice Cup = 5 String Hoppers/1 Roti/1 cup Noodles/¾ cup Grains/¾ cup Milk Rice; *Please avoid consuming instant foods and limit your intake of sugary foods and heavily fried or excessively oily dishes.",
};
const outputValue = response.data.prediction;
const customText = outputTexts[outputValue] || 'Default Text for Other Outputs';
setOtherModelResult(customText);
console.log(response.data.prediction);
})
.catch(error => {
console.error('Error sending data to other model:', error);
alert('Error occurred while sending data to other model.');
});
};
return (
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button title="Pick CBC image" onPress={() => pickImage('CBC')} />
{imageCBC && <Image source={{ uri: imageCBC }} style={{ width: 200, height: 200 }} />}
{resultCBC && <Text>Hemoglobin:{resultCBC}</Text>}
<Button title="Pick OGTT image" onPress={() => pickImage('OGTT')} />
{imageOGTT && <Image source={{ uri: imageOGTT }} style={{ width: 200, height: 200 }} />}
{resultOGTT && <Text>Glucose:{resultOGTT}</Text>}
<TextInput
placeholder="Enter BMI"
onChangeText={text => setBMI(text)}
value={bmi}
keyboardType="numeric"
/>
<Button title="Send to Other Model" onPress={sendToOtherModel} />
{otherModelResult && (
<View>
<Text>Nutrition Plan:</Text>
<Text>{otherModelResult}</Text>
</View>
)}
</View>
</ScrollView>
);
}
*/
import React, { useState } from 'react';
import { Button, Image, Text, View, TextInput, ScrollView } from 'react-native';
import { Button, Image, Text, View, TextInput, ScrollView,StyleSheet,TouchableOpacity } from 'react-native';
import * as ImagePicker from 'expo-image-picker';
import axios from 'axios';
import { useNavigation } from "@react-navigation/native";
export default function Nutrition({ route }) {
const [imageCBC, setImageCBC] = useState(null);
const [imageOGTT, setImageOGTT] = useState(null);
const [resultCBC, setResultCBC] = useState('');
const [resultOGTT, setResultOGTT] = useState('');
//const [bmi, setBMI] = useState('');
const [otherModelResult, setOtherModelResult] = useState('');
const navigation = useNavigation();
const { bmi } = route.params;
const pickImage = async (reportType) => {
const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
......@@ -189,7 +43,7 @@ export default function Nutrition({ route }) {
name: 'image.jpg',
});
const apiUrl = reportType === 'CBC' ? 'http://192.168.76.76:5004/extract_hemoglobin' : 'http://192.168.76.76:5004/extract_glucose';
const apiUrl = reportType === 'CBC' ? 'http://192.168.1.100:5004/extract_hemoglobin' : 'http://192.168.1.100:5004/extract_glucose';
axios.post(apiUrl, formData, {
headers: {
......@@ -224,7 +78,7 @@ export default function Nutrition({ route }) {
console.log(parseFloat(resultOGTT));
console.log(parseFloat(bmi));
const apiUrl = 'http://192.168.76.76:5005/predict'; // Replace with the actual API endpoint URL of the other model
const apiUrl = 'http://192.168.1.100:5005/predict'; // Replace with the actual API endpoint URL of the other model
axios
.post(apiUrl, {
......@@ -251,8 +105,10 @@ export default function Nutrition({ route }) {
const outputValue = response.data.prediction;
const customText = outputTexts[outputValue] || 'Default Text for Other Outputs';
setOtherModelResult(customText);
// Format the meal plan text with line breaks
const formattedMealPlan = customText.replace(/;/g, '\n');
setOtherModelResult(formattedMealPlan);
// setOtherModelResult(customText);
console.log(response.data.prediction);
})
.catch(error => {
......@@ -262,42 +118,145 @@ export default function Nutrition({ route }) {
};
return (
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button title="Pick CBC image" onPress={() => pickImage('CBC')} />
{imageCBC && <Image source={{ uri: imageCBC }} style={{ width: 200, height: 200 }} />}
{resultCBC && <Text>Hemoglobin:{resultCBC}</Text>}
<Button title="Pick OGTT image" onPress={() => pickImage('OGTT')} />
{imageOGTT && <Image source={{ uri: imageOGTT }} style={{ width: 200, height: 200 }} />}
{resultOGTT && <Text>Glucose:{resultOGTT}</Text>}
<TextInput
placeholder="Enter BMI"
onChangeText={text => setBMI(text)}
value={bmi}
keyboardType="numeric"
/>
<TextInput
placeholder="Enter BMI"
onChangeText={(text) => setBMI(text)}
value={bmi ? bmi.toString() : ""} // Set the BMI value from the route
keyboardType="numeric"
editable={false} // Make the TextInput read-only
/>
<Button title="Send to Other Model" onPress={sendToOtherModel} />
{otherModelResult && (
<View>
<Text>Nutrition Plan:</Text>
<Text>{otherModelResult}</Text>
</View>
)}
</View>
</ScrollView>
);
}
const navigateToPlan = () => {
navigation.navigate("Plan", { nutritionPlan: otherModelResult });
};
return (
<ScrollView contentContainerStyle={styles.scrollViewContent}>
<View style={{ flex: 1 }}>
<View style={styles.container}>
<View style={styles.subContainer}>
<Text style={styles.heading}>Upload Your Blood Report</Text>
<Text style={styles.description}>(*Please Upload Fasting Blood Sugar(OGTT-FBS) or Full Blood Count (FBC) Report)</Text>
<View style={styles.imageCBCContainer}>
<Button title="Pick CBC image" onPress={() => pickImage('CBC')} />
{imageCBC && <Image source={{ uri: imageCBC }} style={{ width: 200, height: 200 }} />}
{resultCBC && <Text style={styles.labelText}>Hemoglobin:{resultCBC}</Text>}
</View>
<View style={styles.imageOGTTContainer}>
<Button title="Pick OGTT image" onPress={() => pickImage('OGTT')}/>
{imageOGTT && <Image source={{ uri: imageOGTT }} style={{ width: 200, height: 200 }} />}
{resultOGTT && <Text style={styles.labelText}>Glucose:{resultOGTT}</Text>}
</View>
<View style={styles.bmiContainer}>
<Text style={styles.bmiText}>BMI:</Text>
<TextInput
placeholder="Enter BMI"
onChangeText={(text) => setBMI(text)}
value={bmi ? bmi.toString() : ""} // Set the BMI value from the route
keyboardType="numeric"
style={styles.labelText}
editable={false} // Make the TextInput read-only
/>
</View>
<TouchableOpacity style={styles.selectButton} onPress={sendToOtherModel}>
<Text style={styles.buttonText}>Save</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.navibutton} onPress={navigateToPlan}>
<Text style={styles.buttonText}>Get Nutrition Plan</Text>
</TouchableOpacity>
</View>
</View>
</View>
</ScrollView>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: "#FFEBFA",
flex:1,
},
subContainer: {
padding: 15,
borderRadius: 15,
marginTop: 15,
marginLeft:15,
marginRight:15,
},
scrollViewContent: {
minHeight: '120%', // Set a minimum height to enable scrolling
},
imageCBCContainer: {
marginTop: 40, // Add some margin between the button and the description
alignItems: 'center', // Center the images horizontally
},
imageOGTTContainer:{
marginTop: 40,
alignItems: 'center', // Center the images horizontally
},
bmiContainer:{
marginTop: 40,
fontWeight: "bold",
fontSize: 12,
},
labelText:{
fontWeight: "bold",
fontSize: 12,
},
bmiText:{
fontWeight: "bold",
fontSize: 15,
},
navibutton:{
backgroundColor: "#FF9DD2",
borderRadius: 5,
padding: 10,
marginTop: 30,
width: "100%",
alignItems: "center",
justifyContent: "center",
},
selectButton: {
borderRadius: 10,
marginTop: 40,
width: "100%",
height: 47,
backgroundColor: "#FF9DD2",
alignItems: "center",
justifyContent: "center",
},
buttonText: {
color: "black",
fontSize: 18,
fontWeight: "bold",
},
heading: {
marginTop: 50,
marginLeft: 60,
color: "black",
fontSize: 35,
fontWeight: "bold",
alignItems: "center"
},
description:{
marginTop: 10,
marginLeft: 50,
color: "black",
fontSize: 15,
align: "right",
}
})
\ No newline at end of file
import React, { useState, useEffect } from "react";
import { View, Text, StyleSheet } from "react-native";
import { ScrollView } from "react-native-gesture-handler";
import { firebase } from "../config";
import React, { useEffect } from 'react';
import { View, Text, Image, ScrollView, TouchableOpacity, StyleSheet } from 'react-native';
import { firebase } from '../config'; // Make sure to import 'firestore' and 'firebase' correctly.
const Plan = ({ bmi }) => {
const [mealPlan, setMealPlan] = useState(null);
export default function Plan({ route }) {
// Extract nutritionPlan from route.params
const { nutritionPlan } = route.params;
useEffect(() => {
// Fetch the meal plan based on the BMI value from Firebase
const fetchMealPlan = async () => {
try {
const mealPlanSnapshot = await firebase
.firestore()
.collection("nutrition_plan")
.where("bmiRange", "==", getBmiRange(bmi))
.get();
// Function to save the nutritionPlan to Firestore
const savePlanToDatabase = async (nutritionPlan) => {
try {
const timestamp = firebase.firestore.FieldValue.serverTimestamp();
const data = {
nutritionPlan: nutritionPlan,
date: timestamp,
};
if (!mealPlanSnapshot.empty) {
// Assuming there's only one matching meal plan, but you can handle multiple results if needed
const mealPlanData = mealPlanSnapshot.docs[0].data();
setMealPlan(mealPlanData);
}
} catch (error) {
console.error("Error fetching meal plan:", error);
}
};
if (bmi) {
fetchMealPlan();
}
}, [bmi]);
// Function to determine the BMI range based on value
const getBmiRange = (bmiValue) => {
// Define your BMI ranges and return the appropriate range based on the value
// Example:
if (bmiValue < 18.5) {
return "Underweight";
} else if (bmiValue >= 18.5 && bmiValue < 24.9) {
return "Normal";
} else if (bmiValue >= 24.9 && bmiValue < 29.9) {
return "Overweight";
} else {
return "Obese";
const docRef = await firebase.firestore().collection("mealPlans").add(data);
console.log("Meal plan saved with ID:", docRef.id);
} catch (error) {
console.error('Error saving Nutrition Plan to Firestore: ', error);
}
};
}
return (
<View style={styles.container}>
<Text style={styles.label}>Meal Plan:</Text>
{mealPlan ? (
<View>
<Text>{mealPlan.breakfast}</Text>
<Text>{mealPlan.lunch}</Text>
<Text>{mealPlan.dinner}</Text>
</View>
) : (
<Text>No meal plan available .</Text>
)}
</View>
<ScrollView contentContainerStyle={styles.container}>
{/* Image at the top */}
<Image
source={require('../assets/bmi.jpg')}
style={styles.image}
/>
{/* Nutrition Plan */}
<Text style={styles.title}>Nutrition Plan:</Text>
<Text style={styles.nutritionPlan}>{nutritionPlan}</Text>
{/* Save Plan Button */}
<TouchableOpacity style={styles.button} onPress={savePlanToDatabase}>
<Text>Save Plan</Text>
</TouchableOpacity>
</ScrollView>
);
};
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
padding: 16,
},
image: {
width: '100%',
height: 200, // Adjust the height as needed
},
label: {
fontSize: 24,
fontWeight: "bold",
marginBottom: 10,
title: {
fontSize: 20,
fontWeight: 'bold',
marginTop: 16,
},
nutritionPlan: {
fontSize: 16,
marginTop: 8,
},
button: {
backgroundColor: "#FF9DD2",
padding: 12,
borderRadius: 8,
alignItems: 'center',
marginTop: 16,
},
buttonText: {
color: 'white',
},
});
export default Plan;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment