Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
from groq import Groq | |
import os | |
# Initialize Groq client | |
client = Groq(api_key=os.getenv("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")) | |
# Function to load and preprocess data | |
def load_data(file): | |
df = pd.read_csv(file) | |
return df | |
# Function to provide detailed health advice based on user data | |
def provide_observed_advice(data): | |
# [Your existing logic] | |
pass | |
# Function to fetch health articles from Groq's API | |
def get_health_articles(query): | |
response = client.chat.completions.create( | |
messages=[ | |
{"role": "system", "content": "You are a helpful assistant."}, | |
{"role": "user", "content": f"Provide a list of recent health articles about {query} with titles and URLs."} | |
], | |
model="llama-3.3-70b-versatile", | |
) | |
articles = response.choices[0].message.content | |
return articles | |
# Streamlit app layout | |
def main(): | |
st.title("Student Health Advisory Assistant") | |
st.subheader("Analyze your well-being and get personalized advice") | |
# File upload | |
uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"]) | |
if uploaded_file: | |
df = load_data(uploaded_file) | |
st.write("Dataset preview:") | |
st.dataframe(df.head()) | |
# User input for analysis | |
st.header("Input Your Details") | |
gender = st.selectbox("Gender", ["Male", "Female"]) | |
age = st.slider("Age", 18, 35, step=1) | |
depression = st.slider("Depression Level (1-10)", 1, 10) | |
anxiety = st.slider("Anxiety Level (1-10)", 1, 10) | |
isolation = st.slider("Isolation Level (1-10)", 1, 10) | |
future_insecurity = st.slider("Future Insecurity Level (1-10)", 1, 10) | |
stress_relief_activities = st.slider("Stress Relief Activities Level (1-10)", 1, 10) | |
# Data dictionary for advice | |
user_data = { | |
"gender": gender, | |
"age": age, | |
"depression": depression, | |
"anxiety": anxiety, | |
"isolation": isolation, | |
"future_insecurity": future_insecurity, | |
"stress_relief_activities": stress_relief_activities, | |
} | |
# Provide advice based on user inputs | |
if st.button("Get Observed Advice"): | |
st.subheader("Health Advice Based on Observations") | |
advice = provide_observed_advice(user_data) | |
for i, tip in enumerate(advice, 1): | |
st.write(f"{i}. {tip}") | |
# Fetch related health articles based on user input | |
st.subheader("Related Health Articles") | |
query = "mental health anxiety depression isolation stress relief" | |
articles = get_health_articles(query) | |
st.write(articles) | |
if __name__ == "__main__": | |
main() | |