Skip to content

Commit

Permalink
Added the create and delete functionality for resume.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZaibyS committed Feb 29, 2024
1 parent 873976c commit b4aa8a8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 19 deletions.
9 changes: 7 additions & 2 deletions jobhunter/SQLiteHandler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import sqlite3
import streamlit as st
from sklearn.metrics.pairwise import cosine_similarity

import config
Expand Down Expand Up @@ -180,12 +181,12 @@ def update_resume_in_db(filename, new_text):
return data

def delete_resume_in_db(filename):
"""Update resume text in the database."""
"""Delete resume from the database."""
conn = sqlite3.connect(config.DATABASE)
cursor = conn.cursor()
cursor.execute(
f"DELETE FROM {config.TABLE_RESUMES} WHERE filename = ?",
(filename),
(filename,), # Add a comma to create a tuple
)
conn.commit()

Expand Down Expand Up @@ -252,6 +253,10 @@ def update_similarity_in_db(filename):
conn = sqlite3.connect(config.DATABASE)
c = conn.cursor()
resume_text = get_resume_text(filename)
if resume_text is None:
# Print a warning or handle the absence of text as needed
st.warning("No file selected or empty text.")
return None
resume_embedding = generate_gpt_embedding(resume_text)
for primary_key in primary_keys:
try:
Expand Down
62 changes: 45 additions & 17 deletions jobhunter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
get_resume_text,
update_resume_in_db,
save_text_to_db,
delete_resume_in_db,
update_similarity_in_db,
)

Expand Down Expand Up @@ -120,6 +121,9 @@ def run_transform():
if "read_resume_button_clicked" not in st.session_state:
st.session_state.read_resume_button_clicked = False

if "update_similarity_resume_button_clicked" not in st.session_state:
st.session_state.update_similarity_resume_button_clicked = True

if 'data_queried' not in st.session_state:
st.session_state['data_queried'] = False

Expand Down Expand Up @@ -195,7 +199,18 @@ def run_transform():
except Exception as e:
logging.error(f"An error occurred: {e}")
st.error(f"An error occurred: {e}")

if st.button("Create Resume"):
st.session_state.create_resume_button_clicked = True

if st.session_state.get('create_resume_button_clicked', False):
file_name = st.text_input("Enter Resume File Name")
new_resume_text = st.text_area("Write Resume Content",)
if st.button("Save Resume"):
save_text_to_db(f"{file_name}.txt", new_resume_text)
logging.info("Resume saved to database!")
del st.session_state['create_resume_button_clicked']

if st.button("Select Resume"):
st.session_state.select_resume_button_clicked = True

Expand All @@ -204,25 +219,38 @@ def run_transform():
available_resumes = fetch_resumes_from_db()
selected_resume = st.selectbox("Choose a resume:", available_resumes)

if st.button("Read Resume"):
st.session_state.read_resume_button_clicked = True

if st.session_state.get('read_resume_button_clicked', False):
resume_text = get_resume_text(selected_resume)
st.text_area("Resume Content", resume_text, height=500)

if st.button("Edit Resume"):
st.session_state.editing_resume = selected_resume

if 'editing_resume' in st.session_state and st.session_state.editing_resume == selected_resume:
new_text = st.text_area("Update Resume Content", get_resume_text(selected_resume), height=500)
if st.button("Save Update"):
update_resume_in_db(selected_resume, new_text)
st.success("Resume updated successfully!")
del st.session_state['editing_resume']

if st.button("Use Selected Resume"):
st.session_state.use_select_resume_button_clicked = True

if st.session_state.get('use_select_resume_button_clicked', False):
if st.button("Read Resume"):
st.session_state.read_resume_button_clicked = True

if st.session_state.get('read_resume_button_clicked', False):
resume_text = get_resume_text(selected_resume)
st.text_area("Resume Content", resume_text, height=500)
del st.session_state['read_resume_button_clicked']

if st.button("Edit Resume"):
st.session_state.editing_resume = selected_resume

if 'editing_resume' in st.session_state and st.session_state.editing_resume == selected_resume:
new_text = st.text_area("Update Resume Content", get_resume_text(selected_resume), height=500)
if st.button("Save Update"):
update_resume_in_db(selected_resume, new_text)
st.success("Resume updated successfully!")
del st.session_state['editing_resume']

if st.button("Delete Resume"):
st.session_state.delete_resume_button_clicked = True

if st.session_state.get('delete_resume_button_clicked', False):
delete_resume_in_db(selected_resume)
st.success("Resume deleted successfully!")
del st.session_state['delete_resume_button_clicked']

update_similarity_in_db(selected_resume)


elif choice == "Jobs":
st.title("Jobs")
Expand Down

0 comments on commit b4aa8a8

Please sign in to comment.