Skip to content

Commit

Permalink
Merge pull request #147 from espin086/141-crud-operations-for-resume-…
Browse files Browse the repository at this point in the history
…integrated-into-ui

141 - CRUD Operations for Resume Integrated into UI
  • Loading branch information
espin086 authored Feb 29, 2024
2 parents 1c7557b + f6db911 commit 9767c5e
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
## Features 🌟

### Upload Resume for AI Analysis
![Resume Upload](images/image_ui_resume_load.png)
![Resume Upload](images/image_ui_resume_load.jpg)

![Resume CRUD Operations](images/image_ui_resume_CRUD.jpg)

### Highly Configurable Job Searching 🧐
![Job Search](images/image_ui_job_search.png)
Expand Down
Binary file added images/image_ui_resume_CRUD.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image_ui_resume_load.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/image_ui_resume_load.png
Binary file not shown.
28 changes: 28 additions & 0 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 @@ -166,6 +167,29 @@ def save_text_to_db(filename, text):
conn.commit()
conn.close()

def update_resume_in_db(filename, new_text):
"""Update resume text in the database."""
conn = sqlite3.connect(config.DATABASE)
cursor = conn.cursor()

cursor.execute(
f"UPDATE {config.TABLE_RESUMES} SET content = ? WHERE filename = ?",
(new_text, filename),
)
conn.commit()
data = cursor.fetchall()
return data

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


def fetch_resumes_from_db():
"""Fetch resumes from the database."""
Expand Down Expand Up @@ -229,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: 59 additions & 3 deletions jobhunter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
from SQLiteHandler import (
fetch_resumes_from_db,
get_resume_text,
update_resume_in_db,
save_text_to_db,
delete_resume_in_db,
update_similarity_in_db,
)

Expand Down Expand Up @@ -113,6 +115,15 @@ def run_transform():
if "select_resume_button_clicked" not in st.session_state:
st.session_state.select_resume_button_clicked = False

if "save_update_button_clicked" not in st.session_state:
st.session_state.save_update_button_clicked = False

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 @@ -159,8 +170,11 @@ def run_transform():

elif choice == "Resumes":
st.title("Resumes")
if st.button("Upload Resume") or st.session_state.button_clicked:

if st.button("Upload Resume"):
st.session_state.button_clicked = True

if st.session_state.get('button_clicked', False):
uploaded_file = st.file_uploader("Choose a file", type=["pdf", "txt"])
text = " "
logging.info("File uploader initialized")
Expand All @@ -186,15 +200,57 @@ def run_transform():
logging.error(f"An error occurred: {e}")
st.error(f"An error occurred: {e}")

if st.button("Select Resume") or st.session_state.select_resume_button_clicked:
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

if st.session_state.get('select_resume_button_clicked', False):

available_resumes = fetch_resumes_from_db()
selected_resume = st.selectbox("Choose a resume:", available_resumes)

if st.button("Use Selected Resume"):
# Here you can add the code to process the 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 9767c5e

Please sign in to comment.