-
Notifications
You must be signed in to change notification settings - Fork 0
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
rohankokkulabito
wants to merge
3
commits into
main
Choose a base branch
from
UI-Changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
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( | ||
|
@@ -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: | ||
|
@@ -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", | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
Code suggestion