Spaces:
Sleeping
Sleeping
File size: 1,703 Bytes
9f26a6c c7465ad 9f26a6c a15fb10 62d4e66 91207a8 c7465ad 9f26a6c a15fb10 9f26a6c c7465ad a15fb10 c7465ad 9f26a6c c7465ad a15fb10 9f26a6c 91207a8 c7465ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
from fastapi import FastAPI, File, UploadFile, Form
from transformers import pipeline
from typing import List
import json
# Initialize FastAPI app
app = FastAPI()
# Initialize the text generation pipeline with the Qwen model
pipe = pipeline("text-generation", model="Qwen/Qwen2.5-1.5B-Instruct")
# Endpoint to upload CV file and store CV text
@app.post("/upload-cv/")
async def upload_cv(file: UploadFile = File(...)):
content = await file.read()
cv_text = content.decode("utf-8")
return {"cv_text": cv_text}
# Endpoint to compare job descriptions with the CV text
@app.post("/compare/")
async def compare_job_cv(job_descriptions: str = Form(...), cv_text: str = Form(...)):
# Split job descriptions by line
descriptions = job_descriptions.strip().split("\n")
results = []
for description in descriptions:
# Create prompt for the Qwen model
prompt = f"Compare the following job description with this resume. Job Description: {description}. Resume: {cv_text}. Give a match score and brief analysis."
# Generate response using the text generation pipeline
response = pipe(prompt, max_length=100, num_return_sequences=1)
response_content = response[0]["generated_text"]
# Parse response content for score and summary if JSON formatted
try:
response_data = json.loads(response_content)
results.append(response_data)
except json.JSONDecodeError:
results.append({
"Job Description": description,
"Analysis": response_content # Use raw response if JSON parsing fails
})
return {"results": results}
|