Spaces:
Sleeping
Sleeping
# Import necessary packages | |
from ibm_watson_machine_learning.foundation_models import Model | |
import gradio as gr | |
import os | |
# Securely load the API key and project ID | |
watsonx_API = os.getenv("WATSONX_API") | |
project_id= os.getenv("PROJECT_ID") | |
# Model and project settings | |
model_id = "meta-llama/llama-2-13b-chat" # Directly specifying the LLAMA2 model | |
# Generation parameters | |
gen_parms = { | |
"max_new_tokens": 512, # Adjust as needed for the length of the cover letter | |
"temperature": 0.7 # Adjust for creativity | |
} | |
# Initialize the model | |
model = Model(model_id, watsonx_API, 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 Career Advice", | |
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) | |