saherPervaiz commited on
Commit
dac5058
·
verified ·
1 Parent(s): c9108fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -17
app.py CHANGED
@@ -1,10 +1,9 @@
1
  import streamlit as st
2
  import pandas as pd
3
- from groq import Groq
4
- import os
5
 
6
- # Initialize Groq client
7
- client = Groq(api_key="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")
8
 
9
  # Function to load and preprocess data
10
  @st.cache_data
@@ -14,20 +13,45 @@ def load_data(file):
14
 
15
  # Function to provide detailed health advice based on user data
16
  def provide_observed_advice(data):
17
- # [Your existing logic]
18
- pass
19
 
20
- # Function to fetch health articles from Groq's API
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  def get_health_articles(query):
22
- response = client.chat.completions.create(
23
- messages=[
24
- {"role": "system", "content": "You are a helpful assistant."},
25
- {"role": "user", "content": f"Provide a list of recent health articles about {query} with titles and URLs."}
26
- ],
27
- model="llama-3.3-70b-versatile",
28
- )
29
- articles = response.choices[0].message.content
30
- return articles
 
 
 
31
 
32
  # Streamlit app layout
33
  def main():
@@ -73,7 +97,11 @@ def main():
73
  st.subheader("Related Health Articles")
74
  query = "mental health anxiety depression isolation stress relief"
75
  articles = get_health_articles(query)
76
- st.write(articles)
 
 
 
 
77
 
78
  if __name__ == "__main__":
79
  main()
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import requests
 
4
 
5
+ # Set the GROC API Key directly in the code
6
+ GROC_API_KEY = "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" # Replace with your actual GROC API key
7
 
8
  # Function to load and preprocess data
9
  @st.cache_data
 
13
 
14
  # Function to provide detailed health advice based on user data
15
  def provide_observed_advice(data):
16
+ advice = []
 
17
 
18
+ # High depression and anxiety with low stress-relief activities
19
+ if data['depression'] > 7 and data['anxiety'] > 7:
20
+ advice.append("You seem to be experiencing high levels of both depression and anxiety. It's important to consider professional mental health support. You might also benefit from engaging in calming activities like deep breathing, mindfulness, or yoga.")
21
+
22
+ # Moderate depression or anxiety
23
+ elif data['depression'] > 5 or data['anxiety'] > 5:
24
+ advice.append("You are showing moderate levels of depression or anxiety. It would be helpful to develop healthy coping strategies like maintaining a regular sleep schedule, engaging in physical activity, and reaching out to friends or family for support.")
25
+
26
+ # High isolation and low stress-relief activities
27
+ if data['isolation'] > 7 and data['stress_relief_activities'] < 5:
28
+ advice.append("It seems you are feeling isolated, and your engagement in stress-relief activities is low. It's important to connect with friends or join community groups. Incorporate activities that help alleviate stress, such as walking, journaling, or meditation.")
29
+
30
+ # High future insecurity
31
+ if data['future_insecurity'] > 7:
32
+ advice.append("You are feeling a significant amount of insecurity about the future. It can be helpful to break down your larger goals into smaller, manageable tasks. Seeking career counseling or mentorship could provide valuable guidance and reduce anxiety about the future.")
33
+
34
+ # Overall low engagement in stress-relief activities
35
+ if data['stress_relief_activities'] < 5:
36
+ advice.append("Your engagement in stress-relief activities is quite low. It's essential to engage in activities that reduce stress and promote mental wellness, such as hobbies, physical exercise, and relaxation techniques like deep breathing or yoga.")
37
+
38
+ # Ensure we return a list, even if it's empty
39
+ return advice if advice else ["No advice based on your inputs. Please consider consulting a professional."]
40
+
41
+ # Function to fetch health articles from the GROC API based on the query
42
  def get_health_articles(query):
43
+ url = f"https://api.groc.com/search?q={query}"
44
+ headers = {"Authorization": f"Bearer {GROC_API_KEY}"}
45
+
46
+ try:
47
+ response = requests.get(url, headers=headers)
48
+ response.raise_for_status() # Check for any HTTP errors
49
+ data = response.json() # Assuming the API returns JSON
50
+ articles = [{"title": item["title"], "url": item["url"]} for item in data.get("results", [])]
51
+ return articles
52
+ except requests.exceptions.RequestException as e:
53
+ st.error(f"Error fetching articles: {e}")
54
+ return []
55
 
56
  # Streamlit app layout
57
  def main():
 
97
  st.subheader("Related Health Articles")
98
  query = "mental health anxiety depression isolation stress relief"
99
  articles = get_health_articles(query)
100
+ if articles:
101
+ for article in articles:
102
+ st.write(f"- [{article['title']}]({article['url']})")
103
+ else:
104
+ st.write("No articles found. Please check your API key or internet connection.")
105
 
106
  if __name__ == "__main__":
107
  main()