Spaces:
Runtime error
Runtime error
Andrew Wise
commited on
Commit
·
f4df8f3
1
Parent(s):
2178f46
build
Browse files- app.py +64 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import base64
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
openai.api_key = os.environ["api_key"]
|
| 9 |
+
|
| 10 |
+
def main():
|
| 11 |
+
st.set_page_config(page_title="Cover Letter GPT", page_icon=":pencil2:")
|
| 12 |
+
st.markdown(
|
| 13 |
+
"""
|
| 14 |
+
<h1 style='text-align: center;'>Cover Letter GPT</h1>
|
| 15 |
+
<style>
|
| 16 |
+
body {
|
| 17 |
+
color: black;
|
| 18 |
+
background-color: yellow;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
</style>
|
| 22 |
+
""",
|
| 23 |
+
unsafe_allow_html=True
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
company_name = st.text_input("Enter the company name")
|
| 27 |
+
job_position = st.text_input("Enter the job position")
|
| 28 |
+
job_description = st.text_area("Enter the job description")
|
| 29 |
+
qualifications = st.text_area("Enter your qualifications")
|
| 30 |
+
word_count = st.text_input("Enter the word count of cover letter (maximum: 300): ")
|
| 31 |
+
|
| 32 |
+
options = ["Default", "Formal", "Friendly", "Professional", "Humorous"]
|
| 33 |
+
tone = st.selectbox('Select the tone for the letter', options)
|
| 34 |
+
|
| 35 |
+
if st.button("Generate Cover Letter"):
|
| 36 |
+
# Call the OpenAI GPT-3 API to generate the cover letter
|
| 37 |
+
# using the inputs from the user
|
| 38 |
+
if not all([company_name, job_position, job_description, qualifications, word_count]):
|
| 39 |
+
st.warning("Please fill in all the input fields.")
|
| 40 |
+
else:
|
| 41 |
+
generated_text = generate_cover_letter(
|
| 42 |
+
company_name, job_position, job_description, qualifications, word_count, tone
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
# Display the generated cover letter on the page
|
| 46 |
+
#st.write(generated_text)
|
| 47 |
+
st.markdown(f"<div style='background-color:#F5F5F5; padding:10px'>{generated_text}</div>", unsafe_allow_html=True)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def generate_cover_letter(company_name, job_position, job_description, qualifications, word_count, tone):
|
| 51 |
+
prompt = f"Write a cover letter. The following are the instructions:\n 1) Word count: {word_count}\ntone for letter: {tone}\nCompany name: {company_name}\nJob Position: {job_position}\nThe following details the job description:\n{job_description}\nThe following are my qualifications: {qualifications}\n"
|
| 52 |
+
response = openai.Completion.create(
|
| 53 |
+
engine="text-davinci-002",
|
| 54 |
+
prompt=prompt,
|
| 55 |
+
max_tokens=2048,
|
| 56 |
+
temperature=0.85,
|
| 57 |
+
n=1,
|
| 58 |
+
stop=None,
|
| 59 |
+
timeout=60
|
| 60 |
+
)
|
| 61 |
+
return response.choices[0].text
|
| 62 |
+
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
openai==0.10.2
|
| 2 |
+
streamlit==0.89.0
|