Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import io
|
|
| 4 |
import re
|
| 5 |
import json
|
| 6 |
import os
|
| 7 |
-
import gc
|
| 8 |
from huggingface_hub import login
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
|
|
@@ -73,20 +73,31 @@ def analyze_resume(pdf_file, job_desc=None, inference_fn=None):
|
|
| 73 |
resume_text = extract_text_from_pdf(pdf_file)
|
| 74 |
scores, total_score = calculate_scores(resume_text, job_desc)
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
| 81 |
|
| 82 |
try:
|
| 83 |
-
#
|
| 84 |
result = inference_fn(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
return {
|
| 86 |
"score": {"total": total_score, "breakdown": scores},
|
| 87 |
-
"analysis":
|
| 88 |
"raw_text": resume_text[:500]
|
| 89 |
}
|
|
|
|
|
|
|
| 90 |
except Exception as e:
|
| 91 |
return {"error": str(e)}
|
| 92 |
|
|
@@ -97,7 +108,7 @@ with gr.Blocks(theme=gr.themes.Soft(), fill_height=True) as demo:
|
|
| 97 |
gr.Markdown("Powered by mistralai/Mistral-7B-Instruct-v0.3 via Together AI API. Sign in to use.")
|
| 98 |
button = gr.LoginButton("Sign in")
|
| 99 |
|
| 100 |
-
# Load Mistral-7B from Together AI
|
| 101 |
inference = gr.load(
|
| 102 |
"models/mistralai/Mistral-7B-Instruct-v0.3",
|
| 103 |
accept_token=button,
|
|
@@ -120,4 +131,4 @@ with gr.Blocks(theme=gr.themes.Soft(), fill_height=True) as demo:
|
|
| 120 |
queue=True
|
| 121 |
)
|
| 122 |
|
| 123 |
-
demo.launch(share=True)
|
|
|
|
| 4 |
import re
|
| 5 |
import json
|
| 6 |
import os
|
| 7 |
+
import gc
|
| 8 |
from huggingface_hub import login
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
|
|
|
|
| 73 |
resume_text = extract_text_from_pdf(pdf_file)
|
| 74 |
scores, total_score = calculate_scores(resume_text, job_desc)
|
| 75 |
|
| 76 |
+
# Stricter prompt to ensure JSON output
|
| 77 |
+
prompt = f"""Given these scores: {scores}, return a valid JSON object with:
|
| 78 |
+
- "strengths": list of 2 key strengths referencing the scores,
|
| 79 |
+
- "improvements": list of 3 specific improvements,
|
| 80 |
+
- "missing_skills": list of 2 missing skills (use job description if provided: {job_desc or "None"}).
|
| 81 |
+
Output ONLY a valid JSON string, no extra text or markdown."""
|
| 82 |
|
| 83 |
try:
|
| 84 |
+
# Call Together AI inference
|
| 85 |
result = inference_fn(prompt)
|
| 86 |
+
# Debug: Log the raw result
|
| 87 |
+
print(f"Raw inference result: {result}")
|
| 88 |
+
|
| 89 |
+
if not result or result.strip() == "":
|
| 90 |
+
return {"error": "Empty response from inference API"}
|
| 91 |
+
|
| 92 |
+
# Parse the response as JSON
|
| 93 |
+
parsed_result = json.loads(result)
|
| 94 |
return {
|
| 95 |
"score": {"total": total_score, "breakdown": scores},
|
| 96 |
+
"analysis": parsed_result,
|
| 97 |
"raw_text": resume_text[:500]
|
| 98 |
}
|
| 99 |
+
except json.JSONDecodeError as e:
|
| 100 |
+
return {"error": f"Invalid JSON response: {result}"}
|
| 101 |
except Exception as e:
|
| 102 |
return {"error": str(e)}
|
| 103 |
|
|
|
|
| 108 |
gr.Markdown("Powered by mistralai/Mistral-7B-Instruct-v0.3 via Together AI API. Sign in to use.")
|
| 109 |
button = gr.LoginButton("Sign in")
|
| 110 |
|
| 111 |
+
# Load Mistral-7B from Together AI
|
| 112 |
inference = gr.load(
|
| 113 |
"models/mistralai/Mistral-7B-Instruct-v0.3",
|
| 114 |
accept_token=button,
|
|
|
|
| 131 |
queue=True
|
| 132 |
)
|
| 133 |
|
| 134 |
+
demo.launch(share=True)
|