saherPervaiz commited on
Commit
ecf3d04
·
verified ·
1 Parent(s): e1e605f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -44
app.py CHANGED
@@ -1,9 +1,10 @@
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,44 +14,20 @@ def load_data(file):
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
- return advice
39
-
40
- # Function to fetch health articles from the GROC API based on the query
41
  def get_health_articles(query):
42
- url = f"https://api.groc.com/search?q={query}"
43
- headers = {"Authorization": f"Bearer {GROC_API_KEY}"}
44
-
45
- try:
46
- response = requests.get(url, headers=headers)
47
- response.raise_for_status() # Check for any HTTP errors
48
- data = response.json() # Assuming the API returns JSON
49
- articles = [{"title": item["title"], "url": item["url"]} for item in data.get("results", [])]
50
- return articles
51
- except requests.exceptions.RequestException as e:
52
- st.error(f"Error fetching articles: {e}")
53
- return []
54
 
55
  # Streamlit app layout
56
  def main():
@@ -96,11 +73,7 @@ def main():
96
  st.subheader("Related Health Articles")
97
  query = "mental health anxiety depression isolation stress relief"
98
  articles = get_health_articles(query)
99
- if articles:
100
- for article in articles:
101
- st.write(f"- [{article['title']}]({article['url']})")
102
- else:
103
- st.write("No articles found. Please check your API key or internet connection.")
104
 
105
  if __name__ == "__main__":
106
  main()
 
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=os.getenv("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"))
8
 
9
  # Function to load and preprocess data
10
  @st.cache_data
 
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
  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()