Download utils.py from Ahmad140/Agent: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/spaces/Ahmad140/Agent/resolve/main/utils.py
- Command line
-
hf download hf://spaces/Ahmad140/Agent/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/Ahmad140/Agent/resolve/main/utils.py
2.1 kB
| import sqlite3 | |
| import pandas as pd | |
| import pdfplumber | |
| from sentence_transformers import SentenceTransformer | |
| from pinecone import Pinecone, ServerlessSpec | |
| import streamlit as st | |
| # ---------- Embedding Model ---------- | |
| 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") | |
| 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 |