nagasurendra commited on
Commit
50eabc1
·
verified ·
1 Parent(s): f7676b8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -0
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ from dotenv import load_dotenv
3
+ import os
4
+ import gradio as gr
5
+ import time
6
+ from selenium import webdriver
7
+ from selenium.webdriver.common.by import By
8
+ from selenium.webdriver.common.keys import Keys
9
+ from selenium.webdriver.chrome.service import Service
10
+ from selenium.webdriver.chrome.options import Options
11
+ from selenium.webdriver.common.action_chains import ActionChains
12
+
13
+ # Load environment variables
14
+ load_dotenv()
15
+
16
+ # Set up OpenAI API key
17
+ openai.api_key = os.getenv("OPENAI_API_KEY")
18
+
19
+ # Function to generate cover letters
20
+ def generate_cover_letter(job_desc, resume):
21
+ prompt = f"""
22
+ Write a personalized cover letter for the following job description:\n{job_desc}\n
23
+ Based on this resume:\n{resume}
24
+ """
25
+ response = openai.Completion.create(
26
+ engine="text-davinci-003", # You can use GPT-3 or any available OpenAI model
27
+ prompt=prompt,
28
+ max_tokens=300,
29
+ temperature=0.7,
30
+ )
31
+ return response.choices[0].text.strip()
32
+
33
+ # Function to automate LinkedIn application (login, navigate, apply)
34
+ def apply_on_linkedin(job_url, resume, cover_letter):
35
+ # Set up selenium WebDriver options
36
+ chrome_options = Options()
37
+ chrome_options.add_argument("--headless") # Run headless to avoid opening a browser window
38
+
39
+ # Set up WebDriver and go to LinkedIn login page
40
+ driver = webdriver.Chrome(service=Service("path_to_chromedriver"), options=chrome_options)
41
+ driver.get("https://www.linkedin.com/login")
42
+
43
+ # Log into LinkedIn
44
+ driver.find_element(By.ID, "username").send_keys(os.getenv("LINKEDIN_EMAIL"))
45
+ driver.find_element(By.ID, "password").send_keys(os.getenv("LINKEDIN_PASSWORD"))
46
+ driver.find_element(By.XPATH, '//button[@type="submit"]').click()
47
+ time.sleep(3) # Wait for login to complete
48
+
49
+ # Navigate to job application page
50
+ driver.get(job_url)
51
+ time.sleep(3)
52
+
53
+ # Apply if Easy Apply is available
54
+ try:
55
+ apply_button = driver.find_element(By.CLASS_NAME, "jobs-apply-button")
56
+ apply_button.click()
57
+ time.sleep(2)
58
+
59
+ # Fill in the application form (this can be customized)
60
+ resume_input = driver.find_element(By.NAME, "resume")
61
+ resume_input.send_keys(resume) # Path to your resume (can also upload file here)
62
+
63
+ cover_letter_input = driver.find_element(By.NAME, "cover-letter")
64
+ cover_letter_input.send_keys(cover_letter) # Paste generated cover letter
65
+
66
+ submit_button = driver.find_element(By.XPATH, "//button[@aria-label='Submit application']")
67
+ submit_button.click()
68
+
69
+ return "Application submitted successfully!"
70
+ except Exception as e:
71
+ return f"Error applying: {str(e)}"
72
+ finally:
73
+ driver.quit()
74
+
75
+ # Function for the Gradio interface
76
+ def job_app_bot(job_desc, resume):
77
+ cover_letter = generate_cover_letter(job_desc, resume)
78
+ job_url = "https://www.linkedin.com/jobs/view/some-job-id" # Example job URL
79
+ application_status = apply_on_linkedin(job_url, resume, cover_letter)
80
+ return cover_letter, application_status
81
+
82
+ # Create Gradio interface
83
+ interface = gr.Interface(
84
+ fn=job_app_bot,
85
+ inputs=["text", "text"], # Inputs: job description, resume
86
+ outputs=["text", "text"], # Outputs: generated cover letter, application status
87
+ live=True
88
+ )
89
+
90
+ # Launch the interface
91
+ if __name__ == "__main__":
92
+ interface.launch()