File size: 4,342 Bytes
2d63df8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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

    # User input sections for experience
    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:
        # Generate the prompt for each experience and combine them
        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()