Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
|
|
3 |
|
4 |
# Set the GROC API Key directly in the code
|
5 |
GROC_API_KEY = "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" # Replace with your actual GROC API key
|
@@ -36,6 +37,21 @@ def provide_observed_advice(data):
|
|
36 |
|
37 |
return advice
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
# Streamlit app layout
|
40 |
def main():
|
41 |
st.title("Student Health Advisory Assistant")
|
@@ -76,5 +92,15 @@ def main():
|
|
76 |
for i, tip in enumerate(advice, 1):
|
77 |
st.write(f"{i}. {tip}")
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
if __name__ == "__main__":
|
80 |
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
|
|
|
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():
|
57 |
st.title("Student Health Advisory Assistant")
|
|
|
92 |
for i, tip in enumerate(advice, 1):
|
93 |
st.write(f"{i}. {tip}")
|
94 |
|
95 |
+
# Fetch related health articles based on user input
|
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()
|