File size: 2,940 Bytes
9e17994
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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": 0.7,
    "top_p": 0.9,
    "top_k": 50,
    "max_output_tokens": 1024,
    "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 = [
        "Write your career interests shortly.",
        "What is Your Academic Background?",
        "What are your specific skills?",
        "How many hours per week can you dedicate to learning?",
        "Do you prefer short-term or long-term courses?",
        "Do you prefer online or in-person learning?",
        "What is your preferred working environment (e.g., office, remote, hybrid)?",
        "What are your long-term career goals?",
        "How do you prefer to learn new concepts (e.g., reading, hands-on practice, videos)?",
        "What are your hobbies and interests?",
        "What is your preferred learning style (e.g., visual, auditory, kinesthetic)?",
        "What motivates you to learn new things?",
        "What are your strengths and weaknesses?",
    ]

    # Collect user responses
    responses = {q: st.text_area(q, "") for q in questions}

    # 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()