File size: 2,990 Bytes
8e315dc
c4587cb
8e315dc
af0229e
d15000a
751fd01
 
af0229e
c4587cb
af0229e
 
 
 
 
c4587cb
af0229e
 
c4587cb
af0229e
c4587cb
af0229e
 
 
c4587cb
af0229e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
904e1ea
 
 
 
 
af0229e
8a76421
 
 
 
 
 
 
 
af0229e
 
 
8a76421
 
 
 
 
c718b76
af0229e
 
751fd01
8a76421
af0229e
8a76421
faf2156
b30668d
 
8e315dc
af0229e
9e67cb5
8e315dc
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import streamlit as st
from groq import Groq

# Groq API Key (replace with your actual API key)
groq_api_key = "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"  # Replace with your Groq API key

# Initialize Groq client
client = Groq(api_key=groq_api_key)

# Function to send a request to the Groq API and fetch health advice
def get_health_advice_from_groq(anxiety_level, self_esteem, stress_level):
    """Fetch health advice from Groq API based on user input."""
    query = f"Provide personalized health advice based on the following data: anxiety level: {anxiety_level}, self-esteem: {self_esteem}, stress level: {stress_level}."
    
    try:
        # Request to Groq API
        response = client.chat.completions.create(
            messages=[{"role": "user", "content": query}],
            model="llama-3.3-70b-versatile",  # You can use the model that suits your needs
        )
        # Extract and return the health advice from the response
        advice = response.choices[0].message.content
        return advice
    except Exception as e:
        st.error(f"Error fetching advice from Groq: {e}")
        return None

# Function to create the chatbot interface
def health_advice_chatbot():
    st.title("Health Advice Chatbot")
    st.write("Welcome! I'm here to help you with some basic health advice based on your well-being.")

    # User input
    st.write("Please answer the following questions to receive personalized health advice.")
    
    # Anxiety Level (Slider)
    anxiety_level = st.slider("On a scale of 1 to 10, how would you rate your anxiety level?", 1, 10, 5)

    # Self-esteem Level (Slider)
    self_esteem = st.slider("On a scale of 1 to 10, how would you rate your self-esteem?", 1, 10, 5)

    # Stress Level (Radio Buttons with "Low", "Moderate", "High")
    stress_level = st.radio(
        "How would you rate your stress level?", 
        ["Low", "Moderate", "High"]
    )

    # Store user input in session state for persistent state across reruns
    if 'user_data' not in st.session_state:
        st.session_state.user_data = {}

    st.session_state.user_data['anxiety_level'] = anxiety_level
    st.session_state.user_data['self_esteem'] = self_esteem
    st.session_state.user_data['stress_level'] = stress_level

    # Submit button to get health advice
    if st.button("Get Health Advice"):
        # Fetch health advice from Groq API
        advice = get_health_advice_from_groq(
            st.session_state.user_data['anxiety_level'],
            st.session_state.user_data['self_esteem'],
            st.session_state.user_data['stress_level']
        )
        if advice:
            st.subheader("Here is your personalized health advice:")
            st.write(advice)

    # Option to reset form and restart
    if st.button("Start Over"):
        st.session_state.user_data = {}
        st.rerun()

# Main function to run the chatbot
def main():
    health_advice_chatbot()

if __name__ == "__main__":
    main()