saifeddinemk commited on
Commit
5716ab8
1 Parent(s): 8c62899

Fixed app v2

Browse files
Files changed (1) hide show
  1. app.py +28 -36
app.py CHANGED
@@ -1,47 +1,39 @@
1
- from fastapi import FastAPI, File, UploadFile, Form
2
- from transformers import pipeline
3
  from typing import List
4
  import json
5
 
6
  # Initialize FastAPI app
7
  app = FastAPI()
8
 
9
- # Initialize the text generation pipeline with the Qwen model
10
- pipe = pipeline("text-generation", model="Qwen/Qwen2.5-1.5B-Instruct")
 
 
 
11
 
12
- # Endpoint to upload CV file and store CV text
13
- @app.post("/upload-cv/")
14
- async def upload_cv(file: UploadFile = File(...)):
15
- content = await file.read()
16
- cv_text = content.decode("utf-8")
17
- return {"cv_text": cv_text}
18
-
19
- # Endpoint to compare job descriptions with the CV text
20
- @app.post("/compare/")
21
- async def compare_job_cv(job_descriptions: str = Form(...), cv_text: str = Form(...)):
22
- # Split job descriptions by line
23
- descriptions = job_descriptions.strip().split("\n")
24
- results = []
25
 
26
- for description in descriptions:
27
- # Create prompt for the Qwen model
28
- prompt = f"Compare the following job description with this resume. Job Description: {description}. Resume: {cv_text}. Give a match score and brief analysis."
29
-
30
- # Generate response using the text generation pipeline
31
- response = pipe(prompt, max_length=100, num_return_sequences=1)
32
- response_content = response[0]["generated_text"]
33
-
34
- # Parse response content for score and summary if JSON formatted
35
- try:
36
- response_data = json.loads(response_content)
37
- results.append(response_data)
38
- except json.JSONDecodeError:
39
- results.append({
40
- "Job Description": description,
41
- "Analysis": response_content # Use raw response if JSON parsing fails
42
- })
43
 
44
- return {"results": results}
45
 
46
-
47
 
 
1
+ from fastapi import FastAPI, Form
2
+ from llama_cpp import Llama
3
  from typing import List
4
  import json
5
 
6
  # Initialize FastAPI app
7
  app = FastAPI()
8
 
9
+ # Load the Llama model
10
+ llm = Llama.from_pretrained(
11
+ repo_id="HuggingFaceTB/SmolLM2-360M-Instruct-GGUF",
12
+ filename="smollm2-360m-instruct-q8_0.gguf", # Replace with the actual path to your GGUF file
13
+ )
14
 
15
+ # Endpoint to generate response from model based on user input
16
+ @app.post("/ask/")
17
+ async def ask_question(prompt: str = Form(...)):
18
+ # Format the prompt as a chat message
19
+ messages = [
20
+ {"role": "user", "content": prompt}
21
+ ]
22
+
23
+ # Generate a response using Llama
24
+ response = llm.create_chat_completion(messages=messages)
25
+ response_content = response["choices"][0]["message"]["content"]
 
 
26
 
27
+ return {"response": response_content}
28
+
29
+ # Endpoint to test a simple query (optional)
30
+ @app.get("/test/")
31
+ async def test():
32
+ # Test the model with a simple question
33
+ messages = [{"role": "user", "content": "What is the capital of France?"}]
34
+ response = llm.create_chat_completion(messages=messages)
35
+ response_content = response["choices"][0]["message"]["content"]
 
 
 
 
 
 
 
 
36
 
37
+ return {"test_response": response_content}
38
 
 
39