import os import streamlit as st import google.generativeai as genai from dotenv import load_dotenv # Load environment variables load_dotenv() api_key = os.getenv("GEMINI_API_KEY") # Check if API key is set if not api_key: st.error("API key not found. Please set GEMINI_API_KEY in your .env file.") st.stop() # Configure the generative AI model genai.configure(api_key=api_key) generation_config = { "temperature": 1, "top_p": 0.95, "top_k": 64, "max_output_tokens": 8192, "response_mime_type": "text/plain", } try: model = genai.GenerativeModel( model_name="gemini-1.5-flash", generation_config=generation_config ) except Exception as e: st.error(f"Failed to load model: {str(e)}") st.stop() # Main function for Streamlit app def main(): st.title("Personalized Course Recommendation System") # List of questions for the user questions = [ "How would you want your course look like? ", "From previous semesters which course was your favorite?", "list some of your strongest skills or competencies.", "If you had unlimited resources, what research topic would you dedicate your time to?", "Where do you envision yourself five years from now?", "When face an intellectual problem what strategies do you naturally tend to employ to find solutions?", # "What is your specific skills?", # "How much time can you give to learning?", # "Your preferred working environment", # "What are your long-term goals?", # "How do you prefer to learn new concepts?" ] # Collect user responses responses = {q: st.text_area(q, "") for q in questions} print(responses) # Button to get recommendations if st.button("Get Career Path Recommendation"): if all(responses.values()): with st.spinner("Generating recommendations..."): try: # Start chat session and send the message chat_session = model.start_chat( history=[{"role": "user", "parts": [{"text": f"{q}: {a}"} for q, a in responses.items()]}] ) response = chat_session.send_message("Based on the answers provided, which major Subject of Department of Computer Science & Engineering should the user can take?") recommendation = response.text.strip() # Display the recommendation st.subheader("Career Path Recommendation:") st.write(recommendation) except Exception as e: st.error(f"An error occurred while generating recommendations: {str(e)}") else: st.error("Please answer all the questions to get a recommendation.") # Run the app if __name__ == "__main__": main()