|
import streamlit as st |
|
import google.generativeai as genai |
|
import os |
|
|
|
|
|
def check_all_responses_filled(responses): |
|
return all(responses) and all([all(responses[respondent]) for respondent in respondents]) |
|
|
|
|
|
def configure_genai_api(): |
|
api_key = os.getenv("GENAI_API_KEY") |
|
|
|
if api_key is None: |
|
st.error("API key not found. Please set the GENAI_API_KEY environment variable.") |
|
return None |
|
else: |
|
genai.configure(api_key=api_key) |
|
|
|
generation_config = { |
|
"temperature": 0.9, |
|
"top_p": 1, |
|
"top_k": 40, |
|
"max_output_tokens": 2048, |
|
} |
|
|
|
safety_settings = [ |
|
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, |
|
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, |
|
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, |
|
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, |
|
] |
|
|
|
return genai.GenerativeModel(model_name="gemini-1.0-pro", |
|
generation_config=generation_config, |
|
safety_settings=safety_settings) |
|
|
|
|
|
def combine_responses(saved_data): |
|
def extract_strings(data): |
|
if isinstance(data, dict): |
|
return " ".join([extract_strings(value) for value in data.values()]) |
|
elif isinstance(data, list): |
|
return " ".join([extract_strings(item) for item in data]) |
|
elif isinstance(data, str): |
|
return data |
|
else: |
|
return "" |
|
|
|
combined_responses = [] |
|
for section, responses in saved_data.items(): |
|
for response in responses.values(): |
|
combined_responses.append(extract_strings(response)) |
|
return " ".join(combined_responses) |
|
|
|
|
|
def app(): |
|
st.header("Summary of Your Professional Profile") |
|
|
|
|
|
model = configure_genai_api() |
|
if not model: |
|
return |
|
|
|
|
|
all_responses = { |
|
'core_values': st.session_state.get('core_values_responses'), |
|
'strengths': st.session_state.get('strength_responses'), |
|
'partner_assessment': st.session_state.get('stories_feedback'), |
|
'network_feedback': st.session_state.get('network_feedback'), |
|
'skills': st.session_state.get('core_skills_responses'), |
|
'priorities': st.session_state.get('priorities_data_saved'), |
|
'preferences': st.session_state.get('preferences_responses'), |
|
} |
|
|
|
|
|
for section, responses in all_responses.items(): |
|
if responses: |
|
st.subheader(f"Your {section.replace('_', ' ').title()}:") |
|
if isinstance(responses, dict): |
|
for question, response in responses.items(): |
|
st.text(f"Q: {question}") |
|
st.text(f"A: {response}") |
|
elif isinstance(responses, list): |
|
for response in responses: |
|
st.text(response) |
|
st.write("---") |
|
|
|
|
|
all_responses_filled = all(responses is not None for responses in all_responses.values()) |
|
|
|
if st.button("Generate My Career Summary") and all_responses_filled: |
|
combined_responses_text = combine_responses(all_responses) |
|
inputs = """ |
|
Based on the following inputs, provide recommendations for job opportunities, core values, strengths, and weaknesses, as well as suggested certifications to help the individual align with their desired career path. |
|
Inputs: |
|
""" |
|
prompt_template = """ |
|
Next Job: |
|
1. List the best suitable job role based on the user's preferences and strengths. |
|
3. Provide a brief explanation of how the job aligns with the user's strengths and values. |
|
|
|
Core Values: |
|
1. List the core values user has |
|
2. Calculate the rating of core values the user possesses based on the recommended job profile. Give the rating in percentage. |
|
3. Identify any core values the user should develop to better align with the recommended job profile. |
|
4. Status: user_has if user has it, user_should_develop, if user should develop it |
|
|
|
Strengths: |
|
1. List the strengths user has. |
|
2. Calculate the rating of strengths the user possesses based on the recommended job profile. Give the rating in percentage. |
|
3. Identify any strengths the user should develop to better align with the recommended job profile. |
|
4. Status: user_has if user has it, user_should_develop, if user should develop it |
|
|
|
Weaknesses: |
|
1. Based on the user's responses, list the weaknesses along with justification. |
|
2. Calculate the rating of weaknesses the user possesses based on the recommended job profile. Give the rating in percentage. |
|
3. Explanation for the same based on the user input. |
|
|
|
Career Path Analysis: |
|
Provide a detailed narrative that connects the user's strengths and values with the suggested career paths. |
|
|
|
Recommended Certifications: |
|
1. Suggest relevant certifications from Udacity, Udemy, and Coursera platforms that can help the user acquire the necessary skills and knowledge for their desired career path. |
|
2. Provide a brief description of each recommended certification, but do not include links. |
|
|
|
""" |
|
prompt = inputs + combined_responses_text + prompt_template |
|
|
|
try: |
|
|
|
response = model.generate_content([prompt]) |
|
if response and hasattr(response, 'parts'): |
|
career_summary = ''.join([part['text'] for part in response.parts]) |
|
st.subheader("Career Summary and Projection") |
|
st.write("Based on all the information you've provided, here's a comprehensive summary and future career projection tailored to you:") |
|
st.info(career_summary) |
|
else: |
|
st.error("The response from the API was not in the expected format.") |
|
except Exception as e: |
|
st.error("An error occurred while generating your career summary. Please try again later.") |
|
st.error(f"Error: {e}") |
|
elif not all_responses_filled: |
|
st.error("Please ensure all sections are completed to receive your comprehensive career summary.") |
|
|
|
if __name__ == "__main__": |
|
app() |