Jaheen07 commited on
Commit
253769c
·
verified ·
1 Parent(s): 012a5fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -74
app.py CHANGED
@@ -1,74 +1,74 @@
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": 1,
19
- "top_p": 0.95,
20
- "top_k": 64,
21
- "max_output_tokens": 8192,
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("Career Path Recommendation System")
37
-
38
- # List of questions for the user
39
- questions = [
40
- "Tell me about yourself. (Your characteristics, your preferred working environment, your likings, your dislikings, your team work nature, your dedication level etc.)",
41
- "Tell me something about your career interests.",
42
- "What types of work satisfy you most?",
43
- "How many specific skills do you have and what are those?",
44
- "Elaborate the best professional skill you have.",
45
- "Elaborate the lowest professional skill you have.",
46
- "What are your long-term goals?"
47
- ]
48
-
49
- # Collect user responses
50
- responses = {q: st.text_area(q, "") for q in questions}
51
-
52
- # Button to get recommendations
53
- if st.button("Get Career Path Recommendation"):
54
- if all(responses.values()):
55
- with st.spinner("Generating recommendations..."):
56
- try:
57
- # Start chat session and send the message
58
- chat_session = model.start_chat(
59
- history=[{"role": "user", "parts": [{"text": f"{q}: {a}"} for q, a in responses.items()]}]
60
- )
61
- response = chat_session.send_message("Based on the answers provided, what career path should the user choose?")
62
- recommendation = response.text.strip()
63
-
64
- # Display the recommendation
65
- st.subheader("Career Path Recommendation:")
66
- st.write(recommendation)
67
- except Exception as e:
68
- st.error(f"An error occurred while generating recommendations: {str(e)}")
69
- else:
70
- st.error("Please answer all the questions to get a recommendation.")
71
-
72
- # Run the app
73
- if __name__ == "__main__":
74
- 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": 1,
19
+ "top_p": 0.95,
20
+ "top_k": 64,
21
+ "max_output_tokens": 8192,
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("Career Path 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 is your specific skills?",
43
+ "How much time can you give to learning?",
44
+ "Your preferred working environment",
45
+ "What are your long-term goals?",
46
+ "How do you prefer to learn new concepts?"
47
+ ]
48
+
49
+ # Collect user responses
50
+ responses = {q: st.text_area(q, "") for q in questions}
51
+
52
+ # Button to get recommendations
53
+ if st.button("Get Career Path Recommendation"):
54
+ if all(responses.values()):
55
+ with st.spinner("Generating recommendations..."):
56
+ try:
57
+ # Start chat session and send the message
58
+ chat_session = model.start_chat(
59
+ history=[{"role": "user", "parts": [{"text": f"{q}: {a}"} for q, a in responses.items()]}]
60
+ )
61
+ response = chat_session.send_message("Based on the answers provided, what career path should the user choose?")
62
+ recommendation = response.text.strip()
63
+
64
+ # Display the recommendation
65
+ st.subheader("Career Path Recommendation:")
66
+ st.write(recommendation)
67
+ except Exception as e:
68
+ st.error(f"An error occurred while generating recommendations: {str(e)}")
69
+ else:
70
+ st.error("Please answer all the questions to get a recommendation.")
71
+
72
+ # Run the app
73
+ if __name__ == "__main__":
74
+ main()