Spaces:
Sleeping
Sleeping
saifeddinemk
commited on
Commit
•
5716ab8
1
Parent(s):
8c62899
Fixed app v2
Browse files
app.py
CHANGED
@@ -1,47 +1,39 @@
|
|
1 |
-
from fastapi import FastAPI,
|
2 |
-
from
|
3 |
from typing import List
|
4 |
import json
|
5 |
|
6 |
# Initialize FastAPI app
|
7 |
app = FastAPI()
|
8 |
|
9 |
-
#
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
-
# Endpoint to
|
13 |
-
@app.post("/
|
14 |
-
async def
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
descriptions = job_descriptions.strip().split("\n")
|
24 |
-
results = []
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
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 {"
|
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 |
|