Mangesh223 commited on
Commit
b0e1e50
·
verified ·
1 Parent(s): 0855c8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -22
app.py CHANGED
@@ -5,7 +5,6 @@ import docx
5
  import requests
6
  import json
7
 
8
-
9
  # Function to extract text from PDF
10
  def extract_text_from_pdf(file):
11
  pdf_reader = PyPDF2.PdfReader(file)
@@ -31,27 +30,29 @@ def process_uploaded_file(file):
31
 
32
  # Function to call Together API for Mistral inference
33
  def analyze_with_mistral(resume_text, job_description):
34
- # Replace with your Together API key
35
  TOGETHER_API_KEY = os.getenv("HUGGINGFACE_API_KEY")
36
- url = "https://router.huggingface.co/together/v1"
37
 
38
- # Construct the prompt
39
- prompt = f"""
40
- Analyze the following resume against the job description for ATS compatibility.
41
- Provide a detailed breakdown of ATS parameters (keywords, formatting, skills match, experience relevance, education)
42
- and assign a score out of 100 for each, along with an overall score. Return the result in JSON format.
 
 
 
43
 
44
- Resume:
45
- {resume_text}
46
 
47
- Job Description:
48
- {job_description}
49
- """
 
50
 
51
- # API request payload
52
  payload = {
53
  "model": "mistralai/Mistral-7B-Instruct-v0.3",
54
- "prompt": prompt,
55
  "max_tokens": 1000,
56
  "temperature": 0.7,
57
  "top_p": 0.9,
@@ -62,13 +63,11 @@ def analyze_with_mistral(resume_text, job_description):
62
  "Content-Type": "application/json",
63
  }
64
 
65
- # Make the API call
66
  response = requests.post(url, json=payload, headers=headers)
67
 
68
  if response.status_code == 200:
69
  result = response.json()
70
- # Assuming the API returns the generated text in 'output' field
71
- return result.get("output", json.dumps({"error": "No output from API"}, indent=2))
72
  else:
73
  return json.dumps({"error": f"API request failed with status {response.status_code}: {response.text}"}, indent=2)
74
 
@@ -87,7 +86,7 @@ with gr.Blocks(fill_height=True, title="Smart ATS Resume Analyzer") as demo:
87
  gr.Markdown("# Smart ATS Resume Analyzer")
88
  gr.Markdown("Upload your resume (PDF/Word) and enter a job description to get an ATS compatibility score.")
89
  button = gr.LoginButton("Sign in with Hugging Face")
90
-
91
  with gr.Row():
92
  with gr.Column(scale=1):
93
  resume_upload = gr.File(label="Upload Resume (PDF or Word)", file_types=[".pdf", ".docx"])
@@ -95,12 +94,11 @@ with gr.Blocks(fill_height=True, title="Smart ATS Resume Analyzer") as demo:
95
  submit_btn = gr.Button("Analyze Resume")
96
  with gr.Column(scale=2):
97
  output = gr.JSON(label="ATS Analysis Result")
98
-
99
- # Connect the button to the analysis function
100
  submit_btn.click(
101
  fn=analyze_resume,
102
  inputs=[resume_upload, job_desc],
103
  outputs=output
104
  )
105
 
106
- demo.launch()
 
5
  import requests
6
  import json
7
 
 
8
  # Function to extract text from PDF
9
  def extract_text_from_pdf(file):
10
  pdf_reader = PyPDF2.PdfReader(file)
 
30
 
31
  # Function to call Together API for Mistral inference
32
  def analyze_with_mistral(resume_text, job_description):
 
33
  TOGETHER_API_KEY = os.getenv("HUGGINGFACE_API_KEY")
34
+ url = "https://api.together.xyz/v1/chat/completions"
35
 
36
+ # Constructing the message format
37
+ messages = [
38
+ {"role": "system", "content": "You are an AI expert in ATS resume analysis."},
39
+ {"role": "user", "content": f"""
40
+ Analyze the following resume against the job description for ATS compatibility.
41
+ Provide a detailed breakdown of ATS parameters (keywords, formatting, skills match,
42
+ experience relevance, education) and assign a score out of 100 for each, along with an overall score.
43
+ Return the result in JSON format.
44
 
45
+ Resume:
46
+ {resume_text}
47
 
48
+ Job Description:
49
+ {job_description}
50
+ """}
51
+ ]
52
 
 
53
  payload = {
54
  "model": "mistralai/Mistral-7B-Instruct-v0.3",
55
+ "messages": messages,
56
  "max_tokens": 1000,
57
  "temperature": 0.7,
58
  "top_p": 0.9,
 
63
  "Content-Type": "application/json",
64
  }
65
 
 
66
  response = requests.post(url, json=payload, headers=headers)
67
 
68
  if response.status_code == 200:
69
  result = response.json()
70
+ return result.get("choices", [{}])[0].get("message", {}).get("content", "No response from API")
 
71
  else:
72
  return json.dumps({"error": f"API request failed with status {response.status_code}: {response.text}"}, indent=2)
73
 
 
86
  gr.Markdown("# Smart ATS Resume Analyzer")
87
  gr.Markdown("Upload your resume (PDF/Word) and enter a job description to get an ATS compatibility score.")
88
  button = gr.LoginButton("Sign in with Hugging Face")
89
+
90
  with gr.Row():
91
  with gr.Column(scale=1):
92
  resume_upload = gr.File(label="Upload Resume (PDF or Word)", file_types=[".pdf", ".docx"])
 
94
  submit_btn = gr.Button("Analyze Resume")
95
  with gr.Column(scale=2):
96
  output = gr.JSON(label="ATS Analysis Result")
97
+
 
98
  submit_btn.click(
99
  fn=analyze_resume,
100
  inputs=[resume_upload, job_desc],
101
  outputs=output
102
  )
103
 
104
+ demo.launch()