Skip to content

Instantly share code, notes, and snippets.

@nqbao
Last active January 29, 2023 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nqbao/2aa9be635e03fc8da24dedcb7417cf11 to your computer and use it in GitHub Desktop.
Save nqbao/2aa9be635e03fc8da24dedcb7417cf11 to your computer and use it in GitHub Desktop.
streamlit
openai <= 1
import streamlit as st
import openai
if 'current_response' not in st.session_state:
st.session_state.current_response = None
st.title('Resume Generator')
st.write("""
Input your details below and get a resume description generated for you!
""")
api_key = st.text_input("OpenAI API Key", type="password")
job_title = st.text_input("Your current job title", max_chars=60)
job_responsibility = st.text_area("What is your day-to-day work?", max_chars=2000)
model_color = st.slider("Creativity", 0.0, 1.0, 0.3, 0.05)
prompt_style = st.selectbox("Style", ["simple", "bullets", "fancy", "idea", "two paragraphs"])
gen_resume = st.button("Run")
def generate_prompt():
result = f"Below is a short description of a {job_title}:\n"
result += job_responsibility.strip() + "\n"
if prompt_style == "idea":
result += "\nCan you suggest a few ideas for the resume?"
else:
result += "\nWrite a description to be used in a resume."
if prompt_style == "bullets":
result += " The format must be in bullet points."
elif prompt_style == "fancy":
result += " Use fancy words to make the resume look good."
elif prompt_style == "two paragraphs":
result += " Use at least two paragraphs for the description."
return result.strip()
def generate_description(prompt):
openai.api_key = api_key
response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
temperature=model_color,
max_tokens=768,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response
input_prompt = generate_prompt()
if st.checkbox("Show prompt"):
st.write(input_prompt)
if gen_resume:
if not api_key:
st.error("Please enter your OpenAI API key")
elif not job_title or not job_responsibility:
st.error("Please fill job title and job responsibility")
else:
with st.spinner("Generating your resume..."):
st.session_state.current_response = generate_description(input_prompt)
st.success("Done!")
if st.session_state.current_response:
st.write(st.session_state.current_response['choices'][0]['text'].replace("\n", "\n\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment