Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,31 +1,40 @@
|
|
| 1 |
|
| 2 |
from sentence_transformers import SentenceTransformer, util
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
model = SentenceTransformer("mon2hf/devops-job-matcher")
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
score = float(util.cos_sim(job_emb, prof_emb)[0][0])
|
| 13 |
conf = round(score * 100, 1)
|
| 14 |
return {
|
| 15 |
"match_score": conf,
|
| 16 |
-
"apply":
|
| 17 |
-
"label":
|
| 18 |
}
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
inputs=[
|
| 23 |
-
gr.Textbox(label="Job Description", lines=6),
|
| 24 |
-
gr.Textbox(label="Your Profile", lines=6),
|
| 25 |
-
],
|
| 26 |
-
outputs=gr.JSON(label="Match Result"),
|
| 27 |
-
title="DevOps Job Matcher API",
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
demo.queue(default_concurrency_limit=5)
|
| 31 |
-
demo.launch()
|
|
|
|
| 1 |
|
| 2 |
from sentence_transformers import SentenceTransformer, util
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
+
from pydantic import BaseModel
|
| 6 |
+
import uvicorn
|
| 7 |
+
|
| 8 |
+
app = FastAPI()
|
| 9 |
+
|
| 10 |
+
app.add_middleware(
|
| 11 |
+
CORSMiddleware,
|
| 12 |
+
allow_origins=["*"],
|
| 13 |
+
allow_methods=["*"],
|
| 14 |
+
allow_headers=["*"],
|
| 15 |
+
)
|
| 16 |
|
| 17 |
model = SentenceTransformer("mon2hf/devops-job-matcher")
|
| 18 |
|
| 19 |
+
class MatchRequest(BaseModel):
|
| 20 |
+
job_description: str
|
| 21 |
+
profile_text: str
|
| 22 |
+
|
| 23 |
+
@app.get("/")
|
| 24 |
+
def root():
|
| 25 |
+
return {"status": "running", "model": "devops-job-matcher"}
|
| 26 |
+
|
| 27 |
+
@app.post("/match")
|
| 28 |
+
def match_job(req: MatchRequest):
|
| 29 |
+
job_emb = model.encode(req.job_description, convert_to_tensor=True)
|
| 30 |
+
prof_emb = model.encode(req.profile_text, convert_to_tensor=True)
|
| 31 |
score = float(util.cos_sim(job_emb, prof_emb)[0][0])
|
| 32 |
conf = round(score * 100, 1)
|
| 33 |
return {
|
| 34 |
"match_score": conf,
|
| 35 |
+
"apply": conf >= 70,
|
| 36 |
+
"label": "Strong match" if conf >= 80 else "Good match" if conf >= 70 else "Weak match"
|
| 37 |
}
|
| 38 |
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|