Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed latex #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 24 additions & 59 deletions src/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,47 @@
import streamlit_ext as ste
import os
import openai

from doc_utils import extract_text_from_upload
from templates import generate_latex, template_commands
from prompt_engineering import generate_json_resume, tailor_resume
from render import render_latex
import json

if __name__ == '__main__':

def main():
st.set_page_config(
page_title="Resume2website",
page_icon=":pen:",
layout="wide",
initial_sidebar_state="auto",
)

st.markdown(
f"""
# Resume2Website
""",
unsafe_allow_html=True,
)

st.markdown(
"Welcome to Resume2Website! Drop your previous CV below, select one of the templates, and let the LLMs generate your resume for you"
)

st.markdown("# Resume2Website", unsafe_allow_html=True)
st.markdown("Welcome to Resume2Website! Drop your previous CV below, select one of the templates, and let the LLMs generate your resume for you")

uploaded_file = st.file_uploader("Choose a file", type=["pdf", "docx", "txt", "json"])

template_options = list(template_commands.keys())

if uploaded_file is not None:
# Get the CV data that we need to convert to json
if uploaded_file:
text = extract_text_from_upload(uploaded_file)

if len(text) < 50:
st.warning("The text extracted from the uploaded file is too short. Are you sure this is the correct file?", icon="⚠️")
return
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bito Code Review Agent Run #c0d9f6 - 07/12/2024, 09:44 am

🔴 High importance
Issue: The early return statement 'return' inside the 'if len(text) < 50:' block will exit the 'main()' function but not the Streamlit app, potentially leaving the app in an inconsistent state.
Fix: Instead of using 'return', use 'st.stop()' to properly halt the execution of the Streamlit script, ensuring the app remains in a consistent state.
Code suggestion
 @@ -29,0 +29,1 @@
 +            st.stop()


openai_api_model = os.getenv("OPENAI_DEFAULT_MODEL")
if not openai_api_model:
openai_api_model = st.selectbox(
openai_api_model = os.getenv("OPENAI_DEFAULT_MODEL") or st.selectbox(
"Select a model to use for the LLMs (gpt-3.5-turbo is the most well-tested):",
["gpt-3.5-turbo", "gpt-4-turbo", "gpt-4o"],
index=0, # default to the first option
)
["gpt-3.5-turbo", "gpt-4-turbo", "gpt-4o"],
index=0,
)

# If the OpenAI API Key is not set as an environment variable, prompt the user for it
openai_api_key = os.getenv("OPENAI_API_KEY")
if not openai_api_key:
openai_api_key = st.text_input(
"Enter your OpenAI API Key: [(click here to obtain a new key if you do not have one)](https://platform.openai.com/account/api-keys)",
type="password",
)
openai_api_key = os.getenv("OPENAI_API_KEY") or st.text_input(
"Enter your OpenAI API Key: [(click here to obtain a new key if you do not have one)](https://platform.openai.com/account/api-keys)",
type="password",
)

chosen_option = st.selectbox(
"Select a template to use for your resume [(see templates)](/Template_Gallery)",
template_options,
index=0, # default to the first option
index=0,
)

section_ordering = st.multiselect(
Expand All @@ -70,7 +52,6 @@
)

improve_check = st.checkbox("I want to improve the resume with LLMs", value=False)

generate_button = st.button("Generate Resume")

if generate_button:
Expand All @@ -81,30 +62,16 @@

json_resume = generate_json_resume(text, openai_api_key, openai_api_model)
latex_resume = generate_latex(chosen_option, json_resume, section_ordering)

resume_bytes = render_latex(template_commands[chosen_option], latex_resume)

col1, col2, col3 = st.columns(3)

try:
with col1:
btn = ste.download_button(
label="Download PDF",
data=resume_bytes,
file_name="resume.pdf",
mime="application/pdf",
)
except Exception as e:
st.write(e)

with col2:
with col1:
ste.download_button(
label="Download LaTeX Source",
data=latex_resume,
file_name="resume.tex",
mime="application/x-tex",
label="Download PDF",
data=resume_bytes,
file_name="resume.pdf",
mime="application/pdf",
)

with col3:
ste.download_button(
label="Download JSON Source",
Expand All @@ -113,18 +80,16 @@
mime="text/json",
)
except openai.RateLimitError as e:
st.markdown(
"It looks like you do not have OpenAI API credits left. Check [OpenAI's usage webpage for more information](https://platform.openai.com/account/usage)"
)
st.markdown("It looks like you do not have OpenAI API credits left. Check [OpenAI's usage webpage for more information](https://platform.openai.com/account/usage)")
st.write(e)
except openai.NotFoundError as e:
st.warning(
"It looks like you do not have entered you Credit Card information on OpenAI's site. Buy pre-paid credits to use the API and try again.",
icon="💳"
)
st.warning("It looks like you do not have entered your Credit Card information on OpenAI's site. Buy pre-paid credits to use the API and try again.", icon="💳")
st.write(e)
except Exception as e:
st.error("An error occurred while generating the resume. Please try again.")
st.write(e)
else:
st.info("Please upload a file to get started.")

if __name__ == '__main__':
main()
Comment on lines +94 to +95
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bito Code Review Agent Run #c0d9f6 - 07/12/2024, 09:44 am

🔴 High importance
Issue: The 'main()' function is being called without any error handling at the top level. If an unhandled exception occurs within 'main()', it could cause the entire application to crash.
Fix: Wrap the 'main()' function call in a try-except block to catch any unhandled exceptions and log them appropriately. This will ensure that the application does not crash unexpectedly and provides useful error information.
Code suggestion
 @@ -93,3 +93,7 @@
  if __name__ == '__main__':
 -    main()
 +    try:
 +        main()
 +    except Exception as e:
 +        st.error("An unexpected error occurred. Please try again later.")
 +        st.write(e)

79 changes: 0 additions & 79 deletions src/pages/01_Render_JSON_Resume.py

This file was deleted.

7 changes: 0 additions & 7 deletions src/pages/02_Edit_LaTeX_on_Overleaf.py

This file was deleted.

59 changes: 0 additions & 59 deletions src/pages/03_FAQ.py

This file was deleted.

Loading