Spaces:
Running
Running
File size: 1,172 Bytes
30b3b49 |
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 |
import streamlit as st
import requests
import redis
import psycopg2
# Redis Connection
redis_client = redis.Redis(host='redis-19703.c289.us-west-1-2.ec2.redns.redis-cloud.com', port=19703, db=0, decode_responses=True)
# PostgreSQL Connection
conn = psycopg2.connect(database="screening_db", user="user", password="password", host="localhost", port="5432")
cursor = conn.cursor()
HF_API_URL = "https://api-inference.huggingface.co/models/your-hf-model-id"
st.title("AI Candidate Screening")
resume_text = st.text_area("Paste Candidate Resume")
if st.button("Analyze Resume"):
cache_key = f"resume:{resume_text[:20]}" # Hash first 20 chars
cached_response = redis_client.get(cache_key)
if cached_response:
st.write("Cached Response:", cached_response)
else:
response = requests.post(HF_API_URL, json={"inputs": resume_text}).json()
redis_client.set(cache_key, response, ex=3600) # Cache for 1 hour
# Store result in PostgreSQL
cursor.execute("INSERT INTO screenings (resume_text, result) VALUES (%s, %s)", (resume_text, response))
conn.commit()
st.write("AI Response:", response) |