Mangesh223 commited on
Commit
e4e021b
·
verified ·
1 Parent(s): 5db052a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -52
app.py CHANGED
@@ -1,9 +1,8 @@
1
  import gradio as gr
2
  import PyPDF2
3
  import docx
4
- from io import BytesIO
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
- # Hypothetical Mistral API wrapper (replace with actual API call)
32
- class MistralInference:
33
- def __init__(self, model="mistralai/Mistral-7B-Instruct-v0.3", provider="together"):
34
- self.model = model
35
- self.provider = provider
 
 
 
 
 
 
36
 
37
- def analyze(self, resume_text, job_description):
38
- # Simulated prompt to Mistral model
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
- # Simulated response (replace with actual API call)
52
- response = {
53
- "ats_analysis": {
54
- "keywords": {
55
- "score": 85,
56
- "details": "Key terms like 'Python', 'Machine Learning' found, missing 'AWS'."
57
- },
58
- "formatting": {
59
- "score": 90,
60
- "details": "Simple layout, readable by ATS, no complex tables."
61
- },
62
- "skills_match": {
63
- "score": 80,
64
- "details": "Strong match for programming skills, lacks cloud skills."
65
- },
66
- "experience_relevance": {
67
- "score": 75,
68
- "details": "Relevant experience in data science, but duration slightly short."
69
- },
70
- "education": {
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
- mistral = MistralInference()
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()