Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,10 +2,12 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
import os
|
4 |
from groq import Groq
|
5 |
-
import requests
|
6 |
|
7 |
-
# Set the API key
|
8 |
-
|
|
|
|
|
|
|
9 |
|
10 |
# Function to load and preprocess data
|
11 |
@st.cache_data
|
@@ -39,27 +41,24 @@ def provide_observed_advice(data):
|
|
39 |
|
40 |
return advice
|
41 |
|
42 |
-
# Function to
|
43 |
-
def
|
44 |
-
url = f"https://api.groc.com/search?q={query}"
|
45 |
-
headers = {"Authorization": f"Bearer {api_key}"} # Use the demo API key in the header
|
46 |
-
|
47 |
try:
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
return
|
60 |
-
except
|
61 |
-
st.error(f"Error
|
62 |
-
return
|
63 |
|
64 |
# Streamlit app layout
|
65 |
def main():
|
@@ -128,15 +127,10 @@ def main():
|
|
128 |
else:
|
129 |
st.warning("No advice available based on your inputs.")
|
130 |
|
131 |
-
# Fetch
|
132 |
-
st.subheader("
|
133 |
-
|
134 |
-
|
135 |
-
if articles:
|
136 |
-
for article in articles:
|
137 |
-
st.write(f"π [{article['title']}]({article['url']})")
|
138 |
-
else:
|
139 |
-
st.write("No articles found. Please check your API key or internet connection.")
|
140 |
|
141 |
if __name__ == "__main__":
|
142 |
main()
|
|
|
2 |
import pandas as pd
|
3 |
import os
|
4 |
from groq import Groq
|
|
|
5 |
|
6 |
+
# Set the GROQ API key from environment variable
|
7 |
+
groq_api_key = os.getenv("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") # Make sure the GROQ API key is set in your environment
|
8 |
+
|
9 |
+
# Initialize the GROQ client
|
10 |
+
groq_client = Groq(api_key=groq_api_key)
|
11 |
|
12 |
# Function to load and preprocess data
|
13 |
@st.cache_data
|
|
|
41 |
|
42 |
return advice
|
43 |
|
44 |
+
# Function to use the GROQ API for health queries (e.g., for symptoms or wellness queries)
|
45 |
+
def get_health_advice_from_groq(query):
|
|
|
|
|
|
|
46 |
try:
|
47 |
+
# Sending request to GROQ API
|
48 |
+
chat_completion = groq_client.chat.completions.create(
|
49 |
+
messages=[{
|
50 |
+
"role": "user",
|
51 |
+
"content": query
|
52 |
+
}],
|
53 |
+
model="llama-3.3-70b-versatile",
|
54 |
+
)
|
55 |
+
|
56 |
+
# Extracting and returning the response from GROQ API
|
57 |
+
response_content = chat_completion.choices[0].message.content
|
58 |
+
return response_content
|
59 |
+
except Exception as e:
|
60 |
+
st.error(f"Error with GROQ API: {str(e)}")
|
61 |
+
return "Could not fetch advice from GROQ API."
|
62 |
|
63 |
# Streamlit app layout
|
64 |
def main():
|
|
|
127 |
else:
|
128 |
st.warning("No advice available based on your inputs.")
|
129 |
|
130 |
+
# Fetch additional health advice from GROQ API
|
131 |
+
st.subheader("π¬ **Additional Health Advice from GROQ** π¬")
|
132 |
+
groq_advice = get_health_advice_from_groq("Provide wellness tips for managing anxiety and stress.")
|
133 |
+
st.write(f"π‘ {groq_advice}")
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
if __name__ == "__main__":
|
136 |
main()
|