|
import streamlit as st |
|
import google.generativeai as genai |
|
import os |
|
|
|
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 app(): |
|
st.header("LinkedIn Profile Creator") |
|
model = configure_genai_api() |
|
if not model: |
|
return |
|
|
|
|
|
experiences = [] |
|
with st.form("experience_form"): |
|
num_experiences = st.number_input("How many experiences do you want to add?", min_value=1, value=1, step=1) |
|
for i in range(int(num_experiences)): |
|
exp = { |
|
"Title": st.text_input(f"Title {i+1}", placeholder="Ex: Retail Sales Manager"), |
|
"Employment Type": st.selectbox(f"Employment Type {i+1}", ["Please select", "Full-time", "Part-time", "Self-employed", "Freelance", "Contract", "Internship"], index=0), |
|
"Company Name": st.text_input(f"Company Name {i+1}", placeholder="Ex: Microsoft"), |
|
"Location": st.text_input(f"Location {i+1}", placeholder="Ex: London, United Kingdom"), |
|
"Location Type": st.selectbox(f"Location Type {i+1}", ["Please select", "On-site", "Remote", "Hybrid"], index=0), |
|
"Is Current": st.checkbox(f"I am currently working in this role {i+1}"), |
|
"Start Date": st.date_input(f"Start Date {i+1}"), |
|
"End Date": st.date_input(f"End Date {i+1}") if not st.checkbox(f"End current position as of now {i+1}", value=True) else "Present", |
|
"Industry": st.text_input(f"Industry {i+1}", placeholder="Ex: Software Development"), |
|
"Description": st.text_area(f"Description {i+1}", placeholder="Describe your role, responsibilities, achievements...", max_chars=2000), |
|
"Skills": st.text_input(f"Skills {i+1}", placeholder="Add skills separated by commas"), |
|
} |
|
experiences.append(exp) |
|
submitted = st.form_submit_button("Submit") |
|
|
|
if submitted and experiences: |
|
|
|
experience_prompts = [] |
|
for exp in experiences: |
|
experience_prompt = f""" |
|
Title: {exp['Title']} |
|
Employment Type: {exp['Employment Type']} |
|
Company Name: {exp['Company Name']} |
|
Location: {exp['Location']} |
|
Location Type: {exp['Location Type']} |
|
Start Date: {exp['Start Date']} |
|
End Date: {exp['End Date']} |
|
Industry: {exp['Industry']} |
|
Description: {exp['Description']} |
|
Skills: {exp['Skills']} |
|
""" |
|
experience_prompts.append(experience_prompt) |
|
|
|
combined_prompt = " ".join(experience_prompts) |
|
prompt_template = f""" |
|
Generate a professional LinkedIn experience section based on the following details: |
|
{combined_prompt} |
|
""" |
|
|
|
try: |
|
response = model.generate_content([prompt_template]) |
|
st.subheader("Generated Experience Section") |
|
st.write("Based on your input, here's the generated experience section for your LinkedIn profile:") |
|
st.write(response.text) |
|
except Exception as e: |
|
st.error("An error occurred while generating your LinkedIn experience section. Please try again later.") |
|
st.error(f"Error: {e}") |
|
|
|
if __name__ == "__main__": |
|
app() |
|
|