Commit de679caa authored by Balasooriya B.M.D.D's avatar Balasooriya B.M.D.D

Merge branch 'Adding_emotion_detection_model' into 'master'

Adding emotion detection model

See merge request !31
parents ed99f569 8e67ec9d
......@@ -23,4 +23,7 @@ Nutrition/Lib
Nutrition/Scripts
US/Lib
US/Scripts
\ No newline at end of file
US/Scripts
emotion/Lib
emotion/Scripts
\ No newline at end of file
from flask import Flask, request, jsonify
from tensorflow.keras.models import load_model
import cv2
import tensorflow as tf
import numpy as np
app = Flask(__name__)
# Load the pre-trained emotion detection model
model = tf.keras.models.load_model('optimize3_model.h5')
# Define a function to detect emotions from an image
def detect_emotion(image_data):
emotions = ["surprise", "fear", "angry", "neutral", "sad", "disgust", "happy"]
img = cv2.imdecode(np.frombuffer(image_data, np.uint8), -1)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.resize(img, (48, 48))
img = np.reshape(img, (1, 48, 48, 1))
result = model.predict(img)
print(result)
emotion = emotions[np.argmax(result)]
return emotion
@app.route('/detect_emotion', methods=['POST'])
def detect_emotion_endpoint():
try:
image_data = request.files['photo'].read()
detected_emotion = detect_emotion(image_data)
return jsonify({'emotion': detected_emotion})
except Exception as e:
return jsonify({'error': str(e)})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
......@@ -52,7 +52,7 @@ export default function US() {
});
// Replace with your Flask API URL for image processing
const imageProcessingAPIURL = 'http://192.168.8.103:5002/process_image';
const imageProcessingAPIURL = 'https://us-image-extractor-1001-86c5c2fe91b7.herokuapp.com/process_image';
const imageProcessingResponse = await axios.post(imageProcessingAPIURL, formData, {
headers: {
......@@ -95,7 +95,7 @@ export default function US() {
const biometricValue = parseFloat(biometrics[biometric].replace('mm', '').replace(',', '.'));
// Define the API URL for the specific biometric
const biometricAPIURL = `http://192.168.8.103:5003/${biometric}`;
const biometricAPIURL = `https://review-predictor-1002-0349032bf1bf.herokuapp.com/${biometric}`;
const predictionResponse = await axios.post(biometricAPIURL, {
GA: GA,
......@@ -157,8 +157,9 @@ export default function US() {
return (
<ScrollView contentContainerStyle={styles.scrollContainer}>
<View style={styles.container}>
<Text style={styles.title}>Image Picker</Text>
<Button title="Pick an image from the gallery" onPress={pickImage} />
<Text style={styles.title}>Growth Predictor:</Text>
<Text style={styles.normaltext}>Input your baby's UltraSound(US) Image here:</Text>
<Button title="Pick an image" onPress={pickImage} />
{selectedImage && (
<View style={styles.imageContainer}>
<Image source={{ uri: selectedImage }} style={styles.image} />
......@@ -189,8 +190,9 @@ export default function US() {
)}
<Button
title="Go to Target Screen"
title="Graphs"
onPress={navigateToScreen}
style={styles.button}
/>
</View>
</ScrollView>
......@@ -205,7 +207,12 @@ const styles = StyleSheet.create({
},
title: {
fontSize: 24,
marginBottom: 20,
marginTop: 60,
marginBottom: 17,
},
normaltext: {
fontSize: 18,
marginBottom: 15,
},
imageContainer: {
marginVertical: 20,
......@@ -221,7 +228,7 @@ const styles = StyleSheet.create({
marginBottom: 10,
},
extractedValuesContainer: {
marginTop: 20,
marginTop: 5,
padding: 10,
borderWidth: 1,
borderColor: '#ccc',
......@@ -234,7 +241,7 @@ const styles = StyleSheet.create({
marginBottom: 10,
},
responseContainer: {
marginTop: 20,
marginTop: 10,
padding: 10,
borderWidth: 1,
borderColor: '#ccc',
......@@ -254,4 +261,7 @@ const styles = StyleSheet.create({
fontWeight: 'bold',
marginBottom: 10,
},
button: {
marginTop: 30,
},
});
......@@ -110,11 +110,13 @@ const Prescription = () => {
return (<ScrollView contentContainerStyle={styles.container}>
<View style={styles.imageContainer}>
<Text style={styles.title}>Medicine Effect Predictor</Text>
<Text style={styles.normaltext}>Upload your medical prescriptions here</Text>
{image && <Image source={{ uri: image }} style={styles.image} />}
<Button title="Select Image" onPress={pickImage} />
<Button title="Pick Image" onPress={pickImage} style={styles.pickbutton}/>
</View>
<Button
title="Extract Medicine Names, Effects"
title="Predict the Effects"
onPress={extractTextFromImage}
disabled={!image || loading}
/>
......@@ -160,4 +162,15 @@ const styles = StyleSheet.create({
fontWeight: 'bold',
marginBottom: 8,
},
title: {
fontSize: 24,
marginBottom: 70,
},
normaltext: {
fontSize: 18,
marginBottom: 20,
},
pickbutton: {
marginTop: 20,
},
})
......@@ -269,7 +269,7 @@ const LineChartComponent = () => {
{ x: 'Jun', y: 35 },
];
const chartWidth = 50 * lowerLimitData4.length; // Adjust the factor as needed
const chartWidth = 50 * data5.length; // Adjust the factor as needed
const chartHeight = 200; // You can set this to any desired height
const chartConfig = {
......
......@@ -8,7 +8,7 @@ export default function USWelcome () {
const navigation = useNavigation();
const navigateToUS = () => {
navigation.navigate("Us");
navigation.navigate("US");
};
......
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