Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Aula 💡🕊️
Published © MIT

Health Monitor & Interactive Assistant

This project aims to develop a Raspberry Pi-based application that continuously monitors your health.

AdvancedWork in progress20 hours259
Health Monitor & Interactive Assistant

Things used in this project

Story

Read more

Code

Test code

Python
from flask import Flask, request, jsonify
import Hexabitz 
app = Flask(__name__)

# Function to read temperature and heart rate from Hexabitz sensors
def read_hexabitz_sensors():
    
    temperature = Hexabitz.temp()  # Temperature (in Celsius)
    heart_rate = Hexabitz.hr()  # Heart rate (beats per minute)
    return temperature, heart_rate

# Function to generate health advice based on sensor data
def generate_health_advice(temperature, heart_rate):
    advice = ""
    if temperature > 37.5:
        advice += "High temperature detected! Stay hydrated and keep yourself in a cool place.<br>"
    if heart_rate < 60 or heart_rate > 100:
        advice += "Abnormal heart rate detected. Consult a doctor.<br>"
    return advice

@app.route("/", methods=["GET"])
def home():
    # Display health data and chatbot interaction in a colorful webpage
    return """
    <html>
        <head>
            <title>AI Health Monitor</title>
            <style>
                body {
                    font-family: Arial, sans-serif;
                    background-color: #f0f8ff; /* Light blue background */
                    color: #333; /* Dark text color */
                    margin: 0;
                    padding: 20px;
                }
                h1 {
                    color: #007acc; /* Deep blue */
                    text-align: center;
                }
                form {
                    text-align: center;
                    margin-top: 30px;
                }
                label {
                    font-size: 18px;
                }
                input[type="text"] {
                    padding: 10px;
                    border: 1px solid #007acc;
                    border-radius: 5px;
                    width: 300px;
                }
                input[type="submit"] {
                    padding: 10px 20px;
                    color: #fff;
                    background-color: #007acc;
                    border: none;
                    border-radius: 5px;
                    cursor: pointer;
                }
                input[type="submit"]:hover {
                    background-color: #005f99;
                }
                p {
                    font-size: 16px;
                    text-align: center;
                    margin-top: 20px;
                }
            </style>
        </head>
        <body>
            <h1>AI Health Monitor</h1>
            <form action="/chat" method="post">
                <label for="message">Enter your message:</label><br>
                <input type="text" id="message" name="message" required><br><br>
                <input type="submit" value="Send">
            </form>
        </body>
    </html>
    """

@app.route("/chat", methods=["POST"])
def chat():
    # Read sensor data
    temperature, heart_rate = read_hexabitz_sensors()

    # Extract user's message from the form
    user_message = request.form.get("message")

    # Generate advice based on health data
    advice = generate_health_advice(temperature, heart_rate)
    if "how feel" in user_message.lower():
        advice += "Feel free to describe your symptoms, and I'll try to assist you!<br>"
    else:
        advice += "Would you like more health tips?<br>"

    # Display chatbot response in a colorful webpage with health advice
    return f"""
    <html>
        <head>
            <title>Chatbot Response</title>
            <style>
                body {{
                    font-family: Arial, sans-serif;
                    background-color: #f0f8ff; /* Light blue background */
                    color: #333; /* Dark text color */
                    margin: 0;
                    padding: 20px;
                }}
                h1 {{
                    color: #007acc; /* Deep blue */
                    text-align: center;
                }}
                p {{
                    font-size: 16px;
                    text-align: center;
                    margin-top: 20px;
                }}
                a {{
                    text-decoration: none;
                    color: #007acc;
                    font-weight: bold;
                }}
                a:hover {{
                    color: #005f99;
                }}
            </style>
        </head>
        <body>
            <h1>Chatbot Response</h1>
            <p><b>Temperature:</b> {temperature:.2f}°C</p>
            <p><b>Heart Rate:</b> {heart_rate} BPM</p>
            <p><b>Response:</b> {advice}</p>
            <form action="/chat" method="post">
                <label for="message">Enter your message:</label><br>
                <input type="text" id="message" name="message" required><br><br>
                <input type="submit" value="Send">
            </form>
            <p><a href="/">Go Back</a></p>
        </body>
    </html>
    """

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)

H2BR0x-Firmware

H09R9x-Firmware

Credits

Aula 💡🕊️
60 projects • 226 followers
Electronic Engineering
Contact

Comments

Please log in or sign up to comment.