TalentPulse-AI commited on
Commit
c96142f
·
verified ·
1 Parent(s): 11d1183

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -5
app.py CHANGED
@@ -1,11 +1,55 @@
1
- from transformers import pipeline
 
 
 
 
 
 
2
  import gradio as gr
3
 
4
- model = pipeline("text-generation", model="mistralai/Mistral")
 
 
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  def rate_jd(jd, cv):
7
- response = model(f"JD: {jd}\nCV: {cv}", max_length=3000, num_return_sequences=1)
8
- return response[0]["generated_text"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- iface = gr.Interface(fn=rate_jd, inputs=["text", "text"], outputs="text")
11
  iface.launch()
 
1
+ import os
2
+ import random
3
+ import string
4
+ from datetime import datetime
5
+ from supabase import create_client, Client
6
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
7
+ from huggingface_hub import login
8
  import gradio as gr
9
 
10
+ # Load environment variables (for Hugging Face and Supabase integration)
11
+ from dotenv import load_dotenv
12
+ load_dotenv()
13
 
14
+ # Hugging Face Authentication (for private models)
15
+ huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
16
+ login(token=huggingface_token) # Authenticate with Hugging Face
17
+
18
+ # Hugging Face model setup
19
+ model_name = "mistralai/Mistral" # Replace with the correct model path
20
+ model = AutoModelForSequenceClassification.from_pretrained(model_name, use_auth_token=True)
21
+ tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=True)
22
+
23
+ # Supabase setup
24
+ SUPABASE_URL = os.getenv("SUPABASE_URL")
25
+ SUPABASE_KEY = os.getenv("SUPABASE_KEY")
26
+ supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
27
+
28
+ # Function to process the CV and Job Description
29
  def rate_jd(jd, cv):
30
+ # Tokenize the inputs (job description and CV)
31
+ inputs = tokenizer(jd + " " + cv, return_tensors="pt", truncation=True, padding=True, max_length=512)
32
+
33
+ # Run the model to get the match score
34
+ outputs = model(**inputs)
35
+ score = outputs.logits.detach().numpy().tolist()[0][0] # Adjust based on your model's output
36
+
37
+ # Log the action to Supabase
38
+ email = "guest" # Placeholder, can be updated to actual user if authentication is added
39
+ supabase.table('audit_logs').insert({
40
+ "user_email": email,
41
+ "action": "rate_jd",
42
+ "timestamp": datetime.utcnow().isoformat(),
43
+ "details": {"job_description": jd, "cv": cv, "score": score}
44
+ }).execute()
45
+
46
+ return f"Match Score: {score}"
47
+
48
+ # Gradio interface to interact with the model
49
+ iface = gr.Interface(fn=rate_jd,
50
+ inputs=["text", "text"], # Job Description and CV
51
+ outputs="text", # Display the match score
52
+ live=True)
53
 
54
+ # Launch the Gradio interface
55
  iface.launch()