import random import streamlit as st import requests from dotenv import load_dotenv import os # Load environment variables from .env file load_dotenv() # Fetch the API key from the environment API_KEY = os.getenv("GEMINI_API_KEY") GEMINI_API_URL = "https://gemini-api-url.com" # Replace with the actual URL for Gemini API # Define the questions for mood analysis questions = [ "How are you feeling today in one word?", "What's currently on your mind?", "Do you feel calm or overwhelmed right now?", ] # Function to call Gemini API and get recommendations def get_recommendations(user_responses): # Create the payload with user responses data = { "responses": user_responses, } headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } # Call the Gemini API response = requests.post(GEMINI_API_URL, json=data, headers=headers) if response.status_code == 200: return response.json() # Return the JSON response containing suggestions and mood analysis else: st.error(f"Error in calling Gemini API: {response.status_code}") return {} # Streamlit app def main(): st.title("Mood Analysis and Suggestions") st.write("Answer the following 3 questions to help us understand your mood:") # Collect responses responses = [] for i, question in enumerate(questions): response = st.text_input(f"{i+1}. {question}") if response: responses.append(response) # Analyze responses if all questions are answered if len(responses) == len(questions): # Send the responses to the Gemini API for analysis and suggestions analysis_result = get_recommendations(responses) if analysis_result: # Extract mood and recommendations from the response mood = analysis_result.get("mood", "NEUTRAL") suggestions = analysis_result.get("suggestions", []) articles = analysis_result.get("articles", []) videos = analysis_result.get("videos", []) st.write(f"Detected Mood: {mood}") # Display suggestions st.write("### Suggestions") for suggestion in suggestions: st.write(f"- {suggestion}") # Display articles st.write("### Articles") for article in articles: st.write(f"- [{article['title']}]({article['url']})") # Display videos st.write("### Videos") for video in videos: st.write(f"- [{video['title']}]({video['url']})") else: st.write("Please answer all 3 questions to receive suggestions.") if __name__ == "__main__": main()