Spaces:
Runtime error
Runtime error
import openai | |
import streamlit as st | |
import base64 | |
import os | |
openai.api_key = os.environ["api_key"] | |
def main(): | |
st.set_page_config(page_title="Cover Letter GPT", page_icon=":pencil2:") | |
st.markdown( | |
""" | |
<h1 style='text-align: center;'>Cover Letter GPT</h1> | |
<style> | |
body { | |
color: black; | |
background-color: yellow; | |
} | |
</style> | |
""", | |
unsafe_allow_html=True | |
) | |
company_name = st.text_input("Enter the company name") | |
job_position = st.text_input("Enter the job position") | |
job_description = st.text_area("Enter the job description") | |
qualifications = st.text_area("Enter your qualifications") | |
word_count = st.text_input("Enter the word count of cover letter (maximum: 300): ") | |
options = ["Default", "Formal", "Friendly", "Professional", "Humorous"] | |
tone = st.selectbox('Select the tone for the letter', options) | |
if st.button("Generate Cover Letter"): | |
# Call the OpenAI GPT-3 API to generate the cover letter | |
# using the inputs from the user | |
if not all([company_name, job_position, job_description, qualifications, word_count]): | |
st.warning("Please fill in all the input fields.") | |
else: | |
generated_text = generate_cover_letter( | |
company_name, job_position, job_description, qualifications, word_count, tone | |
) | |
# Display the generated cover letter on the page | |
#st.write(generated_text) | |
st.markdown(f"<div style='background-color:#F5F5F5; padding:10px'>{generated_text}</div>", unsafe_allow_html=True) | |
def generate_cover_letter(company_name, job_position, job_description, qualifications, word_count, tone): | |
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" | |
response = openai.Completion.create( | |
engine="text-davinci-002", | |
prompt=prompt, | |
max_tokens=2048, | |
temperature=0.85, | |
n=1, | |
stop=None, | |
timeout=60 | |
) | |
return response.choices[0].text | |
if __name__ == "__main__": | |
main() |