Deepakraj2006 commited on
Commit
11ecf5d
·
verified ·
1 Parent(s): b987c9d

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +77 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import necessary packages
2
+ from ibm_watsonx_ai import Credentials
3
+ from ibm_watsonx_ai import APIClient
4
+ from ibm_watsonx_ai.foundation_models import Model, ModelInference
5
+ from ibm_watsonx_ai.foundation_models.schema import TextChatParameters
6
+ from ibm_watsonx_ai.metanames import GenTextParamsMetaNames
7
+ import gradio as gr
8
+
9
+ # Model and project settings
10
+ model_id = "meta-llama/llama-3-2-11b-vision-instruct" # Directly specifying the LLAMA3 model
11
+
12
+ watsonx_API="L0sx3BXcQRWNmz45mbBLxL1UiZGnftHFQTwITAci-523"
13
+ project_id="ed8f7a2c-e597-4a09-a98f-dbdcef57a0d0"
14
+
15
+ # Set credentials to use the model
16
+ credentials = {
17
+ "url" : "https://au-syd.ml.cloud.ibm.com",
18
+ "apikey": watsonx_API
19
+ }
20
+
21
+ # Generation parameters
22
+ params = TextChatParameters(
23
+ temperature=0.7,
24
+ max_tokens=512
25
+ )
26
+
27
+
28
+ # Initialize the model
29
+ model = ModelInference(
30
+ model_id=model_id,
31
+ credentials=credentials,
32
+ project_id=project_id,
33
+ params=params
34
+ )
35
+
36
+ # Function to generate a customized cover letter
37
+ def generate_cover_letter(company_name, position_name, job_description, resume_content):
38
+ # Craft the prompt for the model to generate a cover letter
39
+ prompt = f"Generate a customized cover letter using the company name: {company_name}, the position applied for: {position_name}, and the job description: {job_description}. Ensure the cover letter highlights my qualifications and experience as detailed in the resume content: {resume_content}. Adapt the content carefully to avoid including experiences not present in my resume but mentioned in the job description. The goal is to emphasize the alignment between my existing skills and the requirements of the role."
40
+
41
+ messages = [
42
+ {
43
+ "role": "user",
44
+ "content": [
45
+ {
46
+ "type": "text",
47
+ "text": prompt
48
+ },
49
+ ]
50
+ }
51
+ ]
52
+
53
+ # Generate a response using the model with parameters
54
+ generated_response = model.chat(messages=messages)
55
+
56
+ # Extract and return the generated text
57
+ cover_letter = generated_response['choices'][0]['message']['content']
58
+
59
+ return cover_letter
60
+
61
+ # Create Gradio interface for the cover letter generation application
62
+ cover_letter_app = gr.Interface(
63
+ fn=generate_cover_letter,
64
+ flagging_mode="never", # Deactivate the flag function in gradio as it is not needed.
65
+ inputs=[
66
+ gr.Textbox(label="Company Name", placeholder="Enter the name of the company..."),
67
+ gr.Textbox(label="Position Name", placeholder="Enter the name of the position..."),
68
+ gr.Textbox(label="Job Description Information", placeholder="Paste the job description here...", lines=10),
69
+ gr.Textbox(label="Resume Content", placeholder="Paste your resume content here...", lines=10),
70
+ ],
71
+ outputs=gr.Textbox(label="Customized Cover Letter"),
72
+ title="Customized Cover Letter Generator",
73
+ description="Generate a customized cover letter by entering the company name, position name, job description and your resume."
74
+ )
75
+
76
+ # Launch the application
77
+ cover_letter_app.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ Gradio
2
+ ibm_watsonx_ai