Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import streamlit as st
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
api_key = os.getenv("GENAI_API_KEY")
|
| 6 |
|
| 7 |
if api_key is None:
|
|
@@ -10,67 +11,96 @@ else:
|
|
| 10 |
# Configure the Google Gemini API
|
| 11 |
genai.configure(api_key=api_key)
|
| 12 |
|
| 13 |
-
|
| 14 |
generation_config = {
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
}
|
| 20 |
|
| 21 |
safety_settings = [
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
]
|
| 27 |
|
| 28 |
model = genai.GenerativeModel(model_name="gemini-1.0-pro",
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
-
# Streamlit app starts here
|
| 33 |
st.title('Career Development Chatbot')
|
| 34 |
|
| 35 |
# Introduction Section
|
| 36 |
name = st.text_input('Hi! I am a Career Development Chatbot. What is your name?', placeholder="Type your name here")
|
| 37 |
-
|
| 38 |
if name:
|
| 39 |
st.write(f"Nice to meet you, {name}!")
|
| 40 |
|
| 41 |
# Strengths Section
|
| 42 |
st.header("Let's explore your strengths.")
|
| 43 |
st.write("Please answer the following questions to help us analyze your strengths.")
|
| 44 |
-
|
| 45 |
-
# Dynamically create text inputs for each question with placeholders for guidance
|
| 46 |
-
questions = [
|
| 47 |
{"label": "What do you enjoy the most?", "placeholder": "E.g., solving problems, teaching, coding"},
|
| 48 |
{"label": "What am I called on to do most often?", "placeholder": "E.g., organize events, technical support"},
|
| 49 |
{"label": "What do I do best?", "placeholder": "E.g., public speaking, designing"},
|
| 50 |
{"label": "What advice or expertise do others seek from me?", "placeholder": "E.g., financial advice, software troubleshooting"},
|
| 51 |
]
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
for question in questions:
|
| 55 |
response = st.text_input(question["label"], placeholder=question["placeholder"])
|
| 56 |
-
|
| 57 |
|
| 58 |
-
# Analyze
|
| 59 |
if st.button("Analyze My Strengths"):
|
| 60 |
-
if all(
|
| 61 |
-
combined_responses = " ".join(
|
| 62 |
prompt_template = f"""Based on the user's responses about their strengths asked in career development form: {combined_responses}, give me top 5 strengths and rate them on the scale of 1-10,
|
| 63 |
After analyzing this, give it in following format:
|
| 64 |
Qualities : corresponding rate,
|
| 65 |
-
then generate a summary
|
| 66 |
-
|
| 67 |
try:
|
| 68 |
# Attempt to generate a report on the user's strengths
|
| 69 |
response = model.generate_content([prompt_template])
|
| 70 |
-
st.
|
|
|
|
| 71 |
st.info(response.text)
|
| 72 |
except Exception as e:
|
| 73 |
st.error("An error occurred while generating your strengths report. Please try again later.")
|
| 74 |
st.error(f"Error: {e}")
|
| 75 |
else:
|
| 76 |
st.error("Please answer all the questions to receive your strengths report.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Load the API key from an environment variable
|
| 6 |
api_key = os.getenv("GENAI_API_KEY")
|
| 7 |
|
| 8 |
if api_key is None:
|
|
|
|
| 11 |
# Configure the Google Gemini API
|
| 12 |
genai.configure(api_key=api_key)
|
| 13 |
|
|
|
|
| 14 |
generation_config = {
|
| 15 |
+
"temperature": 0.9,
|
| 16 |
+
"top_p": 1,
|
| 17 |
+
"top_k": 40,
|
| 18 |
+
"max_output_tokens": 2048,
|
| 19 |
+
}
|
| 20 |
|
| 21 |
safety_settings = [
|
| 22 |
+
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
|
| 23 |
+
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
|
| 24 |
+
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
|
| 25 |
+
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
|
| 26 |
+
]
|
| 27 |
|
| 28 |
model = genai.GenerativeModel(model_name="gemini-1.0-pro",
|
| 29 |
+
generation_config=generation_config,
|
| 30 |
+
safety_settings=safety_settings)
|
| 31 |
|
| 32 |
+
# Streamlit app UI configuration starts here
|
| 33 |
st.title('Career Development Chatbot')
|
| 34 |
|
| 35 |
# Introduction Section
|
| 36 |
name = st.text_input('Hi! I am a Career Development Chatbot. What is your name?', placeholder="Type your name here")
|
|
|
|
| 37 |
if name:
|
| 38 |
st.write(f"Nice to meet you, {name}!")
|
| 39 |
|
| 40 |
# Strengths Section
|
| 41 |
st.header("Let's explore your strengths.")
|
| 42 |
st.write("Please answer the following questions to help us analyze your strengths.")
|
| 43 |
+
strength_questions = [
|
|
|
|
|
|
|
| 44 |
{"label": "What do you enjoy the most?", "placeholder": "E.g., solving problems, teaching, coding"},
|
| 45 |
{"label": "What am I called on to do most often?", "placeholder": "E.g., organize events, technical support"},
|
| 46 |
{"label": "What do I do best?", "placeholder": "E.g., public speaking, designing"},
|
| 47 |
{"label": "What advice or expertise do others seek from me?", "placeholder": "E.g., financial advice, software troubleshooting"},
|
| 48 |
]
|
| 49 |
+
strength_responses = []
|
| 50 |
+
for question in strength_questions:
|
|
|
|
| 51 |
response = st.text_input(question["label"], placeholder=question["placeholder"])
|
| 52 |
+
strength_responses.append(response)
|
| 53 |
|
| 54 |
+
# Analyze Strengths Button
|
| 55 |
if st.button("Analyze My Strengths"):
|
| 56 |
+
if all(strength_responses):
|
| 57 |
+
combined_responses = " ".join(strength_responses)
|
| 58 |
prompt_template = f"""Based on the user's responses about their strengths asked in career development form: {combined_responses}, give me top 5 strengths and rate them on the scale of 1-10,
|
| 59 |
After analyzing this, give it in following format:
|
| 60 |
Qualities : corresponding rate,
|
| 61 |
+
then generate a summary highlighting the strengths of the user """
|
|
|
|
| 62 |
try:
|
| 63 |
# Attempt to generate a report on the user's strengths
|
| 64 |
response = model.generate_content([prompt_template])
|
| 65 |
+
st.subheader("Strengths Report")
|
| 66 |
+
st.write("Based on your responses, here's a detailed summary report about your strengths:")
|
| 67 |
st.info(response.text)
|
| 68 |
except Exception as e:
|
| 69 |
st.error("An error occurred while generating your strengths report. Please try again later.")
|
| 70 |
st.error(f"Error: {e}")
|
| 71 |
else:
|
| 72 |
st.error("Please answer all the questions to receive your strengths report.")
|
| 73 |
+
|
| 74 |
+
# Core Values Section
|
| 75 |
+
st.header("Reflecting on Your Core Values")
|
| 76 |
+
st.write("Your answers will help us understand what drives you in your professional life.")
|
| 77 |
+
core_values_questions = [
|
| 78 |
+
{"label": "What annoys you or gets under your skin at work?", "placeholder": "E.g., lack of communication, inefficiency"},
|
| 79 |
+
{"label": "What brings joy in your work?", "placeholder": "E.g., achieving goals, helping others"},
|
| 80 |
+
{"label": "What could you not live without in your workplace or a work team?", "placeholder": "E.g., teamwork, respect"},
|
| 81 |
+
{"label": "Who do you admire and what do you admire about them?", "placeholder": "E.g., a leader's empathy, a colleague's creativity"},
|
| 82 |
+
]
|
| 83 |
+
core_values_responses = []
|
| 84 |
+
for question in core_values_questions:
|
| 85 |
+
response = st.text_input(question["label"], placeholder=question["placeholder"], key="CV_" + question["label"])
|
| 86 |
+
core_values_responses.append(response)
|
| 87 |
+
|
| 88 |
+
# Analyze Core Values Button
|
| 89 |
+
if st.button("Analyze My Core Values"):
|
| 90 |
+
if all(core_values_responses):
|
| 91 |
+
combined_responses = " ".join(core_values_responses)
|
| 92 |
+
prompt_template = f"""Based on the user's responses about their core values asked in career development form: {combined_responses}, give me top 5 core values and rate them on the scale of 1-10,
|
| 93 |
+
After analyzing this, give it in following format:
|
| 94 |
+
Qualities : corresponding rate,
|
| 95 |
+
then generate a summary highlighting the core values of the user """
|
| 96 |
+
try:
|
| 97 |
+
# Attempt to generate a report on the user's core values
|
| 98 |
+
response = model.generate_content([prompt_template])
|
| 99 |
+
st.subheader("Core Values Report")
|
| 100 |
+
st.write("Based on your responses, here's a detailed summary report about your core values:")
|
| 101 |
+
st.info(response.text)
|
| 102 |
+
except Exception as e:
|
| 103 |
+
st.error("An error occurred while generating your core values report. Please try again later.")
|
| 104 |
+
st.error(f"Error: {e}")
|
| 105 |
+
else:
|
| 106 |
+
st.error("Please answer all the questions to receive your core values report.")
|