Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,20 @@
|
|
1 |
from ibm_watson_machine_learning.foundation_models import Model
|
2 |
from ibm_watson_machine_learning.metanames import GenTextParamsMetaNames as GenParams
|
3 |
from ibm_watson_machine_learning.foundation_models.utils.enums import ModelTypes, DecodingMethods
|
|
|
|
|
4 |
|
5 |
# Set up the API key and project ID for IBM Watson
|
6 |
watsonx_API = "Q7fLgZsmjZJ9L8BhLE_asx91M1C3dlPeYgmSm2wBleyk" # below is the instruction how to get them
|
7 |
project_id= "a5a13c69-59c8-4856-bea6-4fa1f85e2cbb" # like "0blahblah-000-9999-blah-99bla0hblah0"
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
}
|
12 |
|
|
|
13 |
model = Model(
|
14 |
model_id = 'meta-llama/llama-2-13b-chat', # you can also specify like: ModelTypes.LLAMA_2_70B_CHAT
|
15 |
params = generate_params,
|
@@ -20,7 +25,41 @@ model = Model(
|
|
20 |
project_id= project_id
|
21 |
)
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
|
|
1 |
from ibm_watson_machine_learning.foundation_models import Model
|
2 |
from ibm_watson_machine_learning.metanames import GenTextParamsMetaNames as GenParams
|
3 |
from ibm_watson_machine_learning.foundation_models.utils.enums import ModelTypes, DecodingMethods
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
|
7 |
# Set up the API key and project ID for IBM Watson
|
8 |
watsonx_API = "Q7fLgZsmjZJ9L8BhLE_asx91M1C3dlPeYgmSm2wBleyk" # below is the instruction how to get them
|
9 |
project_id= "a5a13c69-59c8-4856-bea6-4fa1f85e2cbb" # like "0blahblah-000-9999-blah-99bla0hblah0"
|
10 |
|
11 |
+
# Generation parameters
|
12 |
+
gen_parms = {
|
13 |
+
"max_new_tokens": 512, # Adjust as needed for the length of the cover letter
|
14 |
+
"temperature": 0.7 # Adjust for creativity
|
15 |
}
|
16 |
|
17 |
+
|
18 |
model = Model(
|
19 |
model_id = 'meta-llama/llama-2-13b-chat', # you can also specify like: ModelTypes.LLAMA_2_70B_CHAT
|
20 |
params = generate_params,
|
|
|
25 |
project_id= project_id
|
26 |
)
|
27 |
|
28 |
+
# Initialize the model
|
29 |
+
model = Model(model_id, credentials, gen_parms, project_id)
|
30 |
+
|
31 |
+
# Function to generate customized career advice
|
32 |
+
def generate_career_advice(field, position_name, current_qualifications, likes, skills):
|
33 |
+
# Craft the prompt for the model
|
34 |
+
prompt = f"Generate a customized career advice using field: {field}, \
|
35 |
+
position_name: {position_name}, \
|
36 |
+
current_qualifications: {current_qualifications}, \
|
37 |
+
likes: {likes}, \
|
38 |
+
skills: {skills}."
|
39 |
+
|
40 |
+
generated_response = model.generate(prompt, gen_parms)
|
41 |
+
|
42 |
+
# Extract the generated text
|
43 |
+
career_advice = generated_response["results"][0]["generated_text"]
|
44 |
+
return career_advice
|
45 |
+
|
46 |
+
|
47 |
+
# Create Gradio interface for the cover letter generation application
|
48 |
+
career_advice_app = gr.Interface(
|
49 |
+
fn=generate_career_advice,
|
50 |
+
allow_flagging="never", # Deactivate the flag function in gradio as it is not needed.
|
51 |
+
inputs=[
|
52 |
+
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'."),
|
53 |
+
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'"),
|
54 |
+
gr.Textbox(label="Current Qualifications (e.g., studying in high school, high school diploma, college diploma, etc.)", placeholder="Enter your current qualifications ..."),
|
55 |
+
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),
|
56 |
+
gr.Textbox(label="Skills (e.g., I am good at math, science, languages, computers, research, hand tools, etc.)", placeholder="Skills ...", lines=10),
|
57 |
+
],
|
58 |
+
outputs=gr.Textbox(label="Customized Career Advice"),
|
59 |
+
title="Customized Career Advice",
|
60 |
+
description="Generate a customized career advice using field, position name, likes and skills"
|
61 |
+
)
|
62 |
+
|
63 |
+
# Launch the application
|
64 |
+
career_advice_app.launch(server_name="0.0.0.0", debug=True, server_port=7860, share=True)
|
65 |
|