File size: 2,104 Bytes
a9a78d7
 
 
 
b7e7663
7b12f0f
 
928919c
a9a78d7
 
 
 
 
 
928919c
a9a78d7
 
 
 
 
 
 
 
b7e7663
a9a78d7
b7e7663
 
a9a78d7
b7e7663
a9a78d7
 
928919c
a9a78d7
 
 
 
 
 
 
928919c
a9a78d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sqlite3
import pandas as pd
import pdfplumber
from sentence_transformers import SentenceTransformer
from pinecone import Pinecone, ServerlessSpec
import streamlit as st

# ---------- Embedding Model ----------
@st.cache_resource
def get_embedding_model():
    return SentenceTransformer('all-MiniLM-L6-v2')

embedding_model = get_embedding_model()

# ---------- Pinecone Setup ----------
PINECONE_API_KEY = st.secrets["PINECONE_API_KEY"]
PINECONE_INDEX_NAME = st.secrets.get("PINECONE_INDEX_NAME", "job-hunt-index")

@st.cache_resource
def get_pinecone_index():
    pc = Pinecone(api_key=PINECONE_API_KEY)
    index_name = PINECONE_INDEX_NAME
    if index_name not in pc.list_indexes().names():
        pc.create_index(
            name=index_name,
            dimension=384,
            metric="cosine",
            spec=ServerlessSpec(cloud="aws", region="us-east-1")
        )
    return pc.Index(index_name)

# ---------- PDF Extraction ----------
def extract_text_from_pdf(pdf_file):
    text = ""
    with pdfplumber.open(pdf_file) as pdf:
        for page in pdf.pages:
            text += page.extract_text() or ""
    return text

# ---------- SQLite ----------
DB_PATH = "/tmp/applications.db"

def init_db():
    conn = sqlite3.connect(DB_PATH)
    c = conn.cursor()
    c.execute('''CREATE TABLE IF NOT EXISTS applications
                 (id INTEGER PRIMARY KEY, job_title TEXT, company TEXT, match_score REAL, status TEXT, tailored_resume_path TEXT, cover_letter_path TEXT)''')
    conn.commit()
    conn.close()

def save_application(job_title, company, match_score, status, tailored_path="", cover_path=""):
    conn = sqlite3.connect(DB_PATH)
    c = conn.cursor()
    c.execute("INSERT INTO applications (job_title, company, match_score, status, tailored_resume_path, cover_letter_path) VALUES (?,?,?,?,?,?)",
              (job_title, company, match_score, status, tailored_path, cover_path))
    conn.commit()
    conn.close()

def get_metrics():
    conn = sqlite3.connect(DB_PATH)
    df = pd.read_sql_query("SELECT * FROM applications", conn)
    conn.close()
    return df