Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from langchain_openai import ChatOpenAI
|
3 |
+
from langchain.prompts import PromptTemplate
|
4 |
+
from langchain_core.output_parsers import StrOutputParser
|
5 |
+
from langchain.chains import LLMChain
|
6 |
+
import os
|
7 |
+
|
8 |
+
# Create Gradio interface function with topic as input
|
9 |
+
def generate_cover_letter(api_key, job_role, company_name, company_context, candidate_profile):
|
10 |
+
# Set the API key as an environment variable
|
11 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
12 |
+
|
13 |
+
# Load the LLM model
|
14 |
+
model_name = "gpt-3.5-turbo"
|
15 |
+
llm = ChatOpenAI(model_name=model_name)
|
16 |
+
|
17 |
+
# Define the chain and LLM
|
18 |
+
prompt = PromptTemplate.from_template("""
|
19 |
+
So, I am applying for {job_role} at {company_name}
|
20 |
+
=================
|
21 |
+
{company_context}
|
22 |
+
=================
|
23 |
+
{candidate_profile}
|
24 |
+
=================
|
25 |
+
From the company profile and my profile, please create a cover letter for the {job_role} position. Ensure that it is well-crafted and engaging for recruiters and hiring managers. Also, verify that my recent work experience and academic background align with the role I am applying for.
|
26 |
+
""")
|
27 |
+
output_parser = StrOutputParser()
|
28 |
+
chain = LLMChain(llm=llm, prompt=prompt)
|
29 |
+
|
30 |
+
output = chain.run(job_role=job_role, company_name=company_name, company_context=company_context, candidate_profile=candidate_profile)
|
31 |
+
return output
|
32 |
+
|
33 |
+
# Create Gradio interface
|
34 |
+
gr.Interface(
|
35 |
+
fn=generate_cover_letter,
|
36 |
+
inputs=[
|
37 |
+
gr.Textbox(label="OpenAI API Key", placeholder="Enter your OpenAI API key here"),
|
38 |
+
gr.Textbox(label="Job Role", placeholder="Ex: Data Scientist, Fullstack Developer, etc."),
|
39 |
+
gr.Textbox(label="Company Name", placeholder="Enter a company name you applying"),
|
40 |
+
gr.Textbox(label="Company Context", placeholder="Enter a brief description of the company"),
|
41 |
+
gr.Textbox(label="Candidate Profile", placeholder="Describe your professional background, key skills, and relevant experiences")
|
42 |
+
],
|
43 |
+
outputs=gr.Textbox(label="Generated Cover Letter", show_copy_button=True),
|
44 |
+
title="Cover Letter Generator",
|
45 |
+
description="Generate a cover letter based on your job role, company, context, and profile."
|
46 |
+
).launch()
|