LvMAC commited on
Commit
9e17994
·
verified ·
1 Parent(s): f9af30e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -80
app.py CHANGED
@@ -1,80 +1,80 @@
1
- import os
2
- import streamlit as st
3
- import google.generativeai as genai
4
- from dotenv import load_dotenv
5
-
6
- # Load environment variables
7
- load_dotenv()
8
- api_key = os.getenv("GEMINI_API_KEY")
9
-
10
- # Check if API key is set
11
- if not api_key:
12
- st.error("API key not found. Please set GEMINI_API_KEY in your .env file.")
13
- st.stop()
14
-
15
- # Configure the generative AI model
16
- genai.configure(api_key=api_key)
17
- generation_config = {
18
- "temperature": 0.7,
19
- "top_p": 0.9,
20
- "top_k": 50,
21
- "max_output_tokens": 1024,
22
- "response_mime_type": "text/plain",
23
- }
24
-
25
- try:
26
- model = genai.GenerativeModel(
27
- model_name="gemini-1.5-flash",
28
- generation_config=generation_config
29
- )
30
- except Exception as e:
31
- st.error(f"Failed to load model: {str(e)}")
32
- st.stop()
33
-
34
- # Main function for Streamlit app
35
- def main():
36
- st.title("Personalized Course Recommendation System")
37
-
38
- # List of questions for the user
39
- questions = [
40
- "Write your career interests shortly.",
41
- "What is Your Academic Background?",
42
- "What are your specific skills?",
43
- "How many hours per week can you dedicate to learning?",
44
- "Do you prefer short-term or long-term courses?",
45
- "Do you prefer online or in-person learning?",
46
- "What is your preferred working environment (e.g., office, remote, hybrid)?",
47
- "What are your long-term career goals?",
48
- "How do you prefer to learn new concepts (e.g., reading, hands-on practice, videos)?",
49
- "What are your hobbies and interests?",
50
- "What is your preferred learning style (e.g., visual, auditory, kinesthetic)?",
51
- "What motivates you to learn new things?",
52
- "What are your strengths and weaknesses?",
53
- ]
54
-
55
- # Collect user responses
56
- responses = {q: st.text_area(q, "") for q in questions}
57
-
58
- # Button to get recommendations
59
- if st.button("Get Career Path Recommendation"):
60
- if all(responses.values()):
61
- with st.spinner("Generating recommendations..."):
62
- try:
63
- # Start chat session and send the message
64
- chat_session = model.start_chat(
65
- history=[{"role": "user", "parts": [{"text": f"{q}: {a}"} for q, a in responses.items()]}]
66
- )
67
- response = chat_session.send_message("Based on the answers provided, what career path should the user choose?")
68
- recommendation = response.text.strip()
69
-
70
- # Display the recommendation
71
- st.subheader("Career Path Recommendation:")
72
- st.write(recommendation)
73
- except Exception as e:
74
- st.error(f"An error occurred while generating recommendations: {str(e)}")
75
- else:
76
- st.error("Please answer all the questions to get a recommendation.")
77
-
78
- # Run the app
79
- if __name__ == "__main__":
80
- main()
 
1
+ import os
2
+ import streamlit as st
3
+ import google.generativeai as genai
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables
7
+ load_dotenv()
8
+ api_key = os.getenv("GEMINI_API_KEY")
9
+
10
+ # Check if API key is set
11
+ if not api_key:
12
+ st.error("API key not found. Please set GEMINI_API_KEY in your .env file.")
13
+ st.stop()
14
+
15
+ # Configure the generative AI model
16
+ genai.configure(api_key=api_key)
17
+ generation_config = {
18
+ "temperature": 0.7,
19
+ "top_p": 0.9,
20
+ "top_k": 50,
21
+ "max_output_tokens": 1024,
22
+ "response_mime_type": "text/plain",
23
+ }
24
+
25
+ try:
26
+ model = genai.GenerativeModel(
27
+ model_name="gemini-1.5-flash",
28
+ generation_config=generation_config
29
+ )
30
+ except Exception as e:
31
+ st.error(f"Failed to load model: {str(e)}")
32
+ st.stop()
33
+
34
+ # Main function for Streamlit app
35
+ def main():
36
+ st.title("Personalized Course Recommendation System")
37
+
38
+ # List of questions for the user
39
+ questions = [
40
+ "Write your career interests shortly.",
41
+ "What is Your Academic Background?",
42
+ "What are your specific skills?",
43
+ "How many hours per week can you dedicate to learning?",
44
+ "Do you prefer short-term or long-term courses?",
45
+ "Do you prefer online or in-person learning?",
46
+ "What is your preferred working environment (e.g., office, remote, hybrid)?",
47
+ "What are your long-term career goals?",
48
+ "How do you prefer to learn new concepts (e.g., reading, hands-on practice, videos)?",
49
+ "What are your hobbies and interests?",
50
+ "What is your preferred learning style (e.g., visual, auditory, kinesthetic)?",
51
+ "What motivates you to learn new things?",
52
+ "What are your strengths and weaknesses?",
53
+ ]
54
+
55
+ # Collect user responses
56
+ responses = {q: st.text_area(q, "") for q in questions}
57
+
58
+ # Button to get recommendations
59
+ if st.button("Get Career Path Recommendation"):
60
+ if all(responses.values()):
61
+ with st.spinner("Generating recommendations..."):
62
+ try:
63
+ # Start chat session and send the message
64
+ chat_session = model.start_chat(
65
+ history=[{"role": "user", "parts": [{"text": f"{q}: {a}"} for q, a in responses.items()]}]
66
+ )
67
+ response = chat_session.send_message("Based on the answers provided, which major Subject of Department of Computer Science & Engineering should the user can take?")
68
+ recommendation = response.text.strip()
69
+
70
+ # Display the recommendation
71
+ st.subheader("Career Path Recommendation:")
72
+ st.write(recommendation)
73
+ except Exception as e:
74
+ st.error(f"An error occurred while generating recommendations: {str(e)}")
75
+ else:
76
+ st.error("Please answer all the questions to get a recommendation.")
77
+
78
+ # Run the app
79
+ if __name__ == "__main__":
80
+ main()