Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import PyPDF2
|
| 3 |
import docx
|
| 4 |
-
|
| 5 |
import json
|
| 6 |
-
from mistral_inference import MistralInference # Hypothetical API wrapper for Mistral model
|
| 7 |
|
| 8 |
# Function to extract text from PDF
|
| 9 |
def extract_text_from_pdf(file):
|
|
@@ -28,60 +27,54 @@ def process_uploaded_file(file):
|
|
| 28 |
else:
|
| 29 |
raise ValueError("Unsupported file format. Please upload a PDF or Word document.")
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 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 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
"score": 95,
|
| 72 |
-
"details": "Matches required degree in Computer Science."
|
| 73 |
-
},
|
| 74 |
-
"overall_score": 85
|
| 75 |
-
}
|
| 76 |
-
}
|
| 77 |
-
return json.dumps(response, indent=2)
|
| 78 |
|
| 79 |
# Main function to analyze resume
|
| 80 |
def analyze_resume(file, job_description):
|
| 81 |
try:
|
| 82 |
resume_text = process_uploaded_file(file)
|
| 83 |
-
|
| 84 |
-
result = mistral.analyze(resume_text, job_description)
|
| 85 |
return result
|
| 86 |
except Exception as e:
|
| 87 |
return json.dumps({"error": str(e)}, indent=2)
|
|
@@ -108,7 +101,4 @@ with gr.Blocks(fill_height=True, title="Smart ATS Resume Analyzer") as demo:
|
|
| 108 |
outputs=output
|
| 109 |
)
|
| 110 |
|
| 111 |
-
# Load Mistral model (hypothetical, adjust based on actual integration)
|
| 112 |
-
gr.load("models/mistralai/Mistral-7B-Instruct-v0.3", accept_token=button, provider="together")
|
| 113 |
-
|
| 114 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import PyPDF2
|
| 3 |
import docx
|
| 4 |
+
import requests
|
| 5 |
import json
|
|
|
|
| 6 |
|
| 7 |
# Function to extract text from PDF
|
| 8 |
def extract_text_from_pdf(file):
|
|
|
|
| 27 |
else:
|
| 28 |
raise ValueError("Unsupported file format. Please upload a PDF or Word document.")
|
| 29 |
|
| 30 |
+
# Function to call Together API for Mistral inference
|
| 31 |
+
def analyze_with_mistral(resume_text, job_description):
|
| 32 |
+
# Replace with your Together API key
|
| 33 |
+
TOGETHER_API_KEY = "your-together-api-key-here"
|
| 34 |
+
url = "https://api.together.xyz/inference"
|
| 35 |
+
|
| 36 |
+
# Construct the prompt
|
| 37 |
+
prompt = f"""
|
| 38 |
+
Analyze the following resume against the job description for ATS compatibility.
|
| 39 |
+
Provide a detailed breakdown of ATS parameters (keywords, formatting, skills match, experience relevance, education)
|
| 40 |
+
and assign a score out of 100 for each, along with an overall score. Return the result in JSON format.
|
| 41 |
|
| 42 |
+
Resume:
|
| 43 |
+
{resume_text}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
Job Description:
|
| 46 |
+
{job_description}
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
# API request payload
|
| 50 |
+
payload = {
|
| 51 |
+
"model": "mistralai/Mistral-7B-Instruct-v0.3",
|
| 52 |
+
"prompt": prompt,
|
| 53 |
+
"max_tokens": 1000,
|
| 54 |
+
"temperature": 0.7,
|
| 55 |
+
"top_p": 0.9,
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
headers = {
|
| 59 |
+
"Authorization": f"Bearer {TOGETHER_API_KEY}",
|
| 60 |
+
"Content-Type": "application/json",
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
# Make the API call
|
| 64 |
+
response = requests.post(url, json=payload, headers=headers)
|
| 65 |
+
|
| 66 |
+
if response.status_code == 200:
|
| 67 |
+
result = response.json()
|
| 68 |
+
# Assuming the API returns the generated text in 'output' field
|
| 69 |
+
return result.get("output", json.dumps({"error": "No output from API"}, indent=2))
|
| 70 |
+
else:
|
| 71 |
+
return json.dumps({"error": f"API request failed with status {response.status_code}: {response.text}"}, indent=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
# Main function to analyze resume
|
| 74 |
def analyze_resume(file, job_description):
|
| 75 |
try:
|
| 76 |
resume_text = process_uploaded_file(file)
|
| 77 |
+
result = analyze_with_mistral(resume_text, job_description)
|
|
|
|
| 78 |
return result
|
| 79 |
except Exception as e:
|
| 80 |
return json.dumps({"error": str(e)}, indent=2)
|
|
|
|
| 101 |
outputs=output
|
| 102 |
)
|
| 103 |
|
|
|
|
|
|
|
|
|
|
| 104 |
demo.launch()
|