File size: 3,259 Bytes
8aeb51c
60de072
df82699
 
51f379b
 
60de072
884bc6d
4f16120
ce79908
30fc153
51f379b
 
 
 
60de072
30fc153
6fa29da
 
51f379b
7e82822
 
 
 
 
78e6035
 
2b7dd70
78e6035
 
 
 
 
 
60de072
51f379b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c767ae8
51f379b
 
 
 
 
60de072
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
import os
from ibm_watson_machine_learning.foundation_models import Model
from ibm_watson_machine_learning.metanames import GenTextParamsMetaNames as GenParams
from ibm_watson_machine_learning.foundation_models.utils.enums import ModelTypes, DecodingMethods
import gradio as gr


# Set up the API key and project ID for IBM Watson
watsonx_API = os.environ.get("watsonx_API") 
project_id = os.environ.get("project_id")

# Generation parameters
gen_parms = {
    "max_new_tokens": 512,  # Adjust as needed for the length of the cover letter
    "temperature": 0.7  # Adjust for creativity
}

# Model and project settings
model_id = "meta-llama/llama-2-13b-chat"

credentials={
        "apikey": watsonx_API,
        "url": "https://us-south.ml.cloud.ibm.com"
    }

model = Model(
    model_id = 'meta-llama/llama-2-13b-chat', # you can also specify like: ModelTypes.LLAMA_2_70B_CHAT
    params = gen_parms,
    credentials={
        "apikey": watsonx_API,
        "url": "https://us-south.ml.cloud.ibm.com"
    },
    project_id= project_id
    )

# Initialize the model
model = Model(model_id, credentials, gen_parms, project_id)

# Function to generate customized career advice
def generate_career_advice(field, position_name, current_qualifications, likes, skills):
    # Craft the prompt for the model 
    prompt = f"Generate a customized career advice using field: {field}, \
    position_name: {position_name}, \
    current_qualifications: {current_qualifications}, \
    likes: {likes}, \
    skills: {skills}."

    generated_response = model.generate(prompt, gen_parms)

    # Extract the generated text
    career_advice = generated_response["results"][0]["generated_text"]
    return career_advice


# Create Gradio interface for the cover letter generation application
career_advice_app = gr.Interface(
    fn=generate_career_advice,
    allow_flagging="never", # Deactivate the flag function in gradio as it is not needed.
    inputs=[
        gr.Textbox(label="Field of Interest (e.g., healthcare, trades, social service, etc., or enter 'not sure')", placeholder="Enter the field which you are interested in... or type 'not sure'."),
        gr.Textbox(label="Position Name (e.g., nurse, personal support worker, software developer, plumber, etc., or enter 'not sure')", placeholder="Enter the name of the position you are interested in... or type 'not sure'"),
        gr.Textbox(label="Current Qualifications (e.g., studying in high school, high school diploma, college diploma, etc.)", placeholder="Enter your current qualifications ..."),
        gr.Textbox(label="Likes (e.g., I like working with my hands, I like to work outside, I like to help people, I like teaching, ...", placeholder="Enter activities you like ...", lines=10),
        gr.Textbox(label="Skills (e.g., I am good at math, science, languages, computers, research, hand tools, etc.)", placeholder="Skills ...", lines=10),
    ],
    outputs=gr.Textbox(label="Customized Career Advice"),
    title="Customized AI-Powered Career Advice - by Wael Nawara",
    description="Generate a customized career advice using field, position name, likes and skills"
)

# Launch the application
career_advice_app.launch(server_name="0.0.0.0", debug=True, server_port=7860, share=True)