Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -42,19 +42,24 @@ def query_gemini_api(user_answers):
|
|
42 |
# Send the request to the Gemini API
|
43 |
response = requests.post(url, headers=headers, json=payload)
|
44 |
|
45 |
-
#
|
46 |
-
print("API Response:", response.json())
|
47 |
-
|
48 |
if response.status_code == 200:
|
49 |
result = response.json()
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
else:
|
53 |
print(f"Error: {response.status_code} - {response.text}")
|
54 |
-
return None
|
55 |
except requests.exceptions.RequestException as e:
|
56 |
print(f"An error occurred: {e}")
|
57 |
-
return None
|
58 |
|
59 |
# Streamlit app for collecting answers
|
60 |
def main():
|
@@ -72,27 +77,21 @@ def main():
|
|
72 |
# If all 3 responses are collected, send them to Gemini for analysis
|
73 |
if len(responses) == len(questions):
|
74 |
st.write("Processing your answers...")
|
75 |
-
|
76 |
# Get mood and recommendations from Gemini API
|
77 |
-
|
78 |
-
|
79 |
-
if result:
|
80 |
-
# Assuming the response contains mood and recommendations
|
81 |
-
mood = result.get("mood", "Unknown")
|
82 |
-
recommendations = result.get("recommendations", [])
|
83 |
|
|
|
84 |
# Display the detected mood
|
85 |
st.write(f"Detected Mood: {mood}")
|
86 |
|
87 |
# Display the recommendations
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
st.write(f"- {recommendation}")
|
92 |
-
else:
|
93 |
-
st.write("No recommendations available.")
|
94 |
else:
|
95 |
-
|
|
|
96 |
else:
|
97 |
st.write("Please answer all 3 questions to receive suggestions.")
|
98 |
|
|
|
42 |
# Send the request to the Gemini API
|
43 |
response = requests.post(url, headers=headers, json=payload)
|
44 |
|
45 |
+
# Wait for the response and process it
|
|
|
|
|
46 |
if response.status_code == 200:
|
47 |
result = response.json()
|
48 |
+
|
49 |
+
# Check if the response contains valid mood and recommendations
|
50 |
+
mood = result.get("mood", None)
|
51 |
+
recommendations = result.get("recommendations", None)
|
52 |
+
|
53 |
+
if mood and recommendations:
|
54 |
+
return mood, recommendations
|
55 |
+
else:
|
56 |
+
return None, None
|
57 |
else:
|
58 |
print(f"Error: {response.status_code} - {response.text}")
|
59 |
+
return None, None
|
60 |
except requests.exceptions.RequestException as e:
|
61 |
print(f"An error occurred: {e}")
|
62 |
+
return None, None
|
63 |
|
64 |
# Streamlit app for collecting answers
|
65 |
def main():
|
|
|
77 |
# If all 3 responses are collected, send them to Gemini for analysis
|
78 |
if len(responses) == len(questions):
|
79 |
st.write("Processing your answers...")
|
80 |
+
|
81 |
# Get mood and recommendations from Gemini API
|
82 |
+
mood, recommendations = query_gemini_api(responses)
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
+
if mood and recommendations:
|
85 |
# Display the detected mood
|
86 |
st.write(f"Detected Mood: {mood}")
|
87 |
|
88 |
# Display the recommendations
|
89 |
+
st.write("### Recommendations to Improve Your Mood:")
|
90 |
+
for recommendation in recommendations:
|
91 |
+
st.write(f"- {recommendation}")
|
|
|
|
|
|
|
92 |
else:
|
93 |
+
# If no valid mood or recommendations are found, do nothing
|
94 |
+
pass
|
95 |
else:
|
96 |
st.write("Please answer all 3 questions to receive suggestions.")
|
97 |
|