Spaces:
Sleeping
Sleeping
Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from llama_cpp import Llama
|
| 4 |
+
from huggingface_hub import hf_hub_download
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# Downloads your specific model
|
| 9 |
+
model_path = hf_hub_download(
|
| 10 |
+
repo_id="devray11/Aevis-Medical-SLM",
|
| 11 |
+
filename="DeepSeek-R1-Distill-Llama-8B.Q4_K_M.gguf"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
# Initializes the AI engine
|
| 15 |
+
llm = Llama(model_path=model_path, n_ctx=2048)
|
| 16 |
+
|
| 17 |
+
class Query(BaseModel):
|
| 18 |
+
prompt: str
|
| 19 |
+
|
| 20 |
+
@app.post("/generate")
|
| 21 |
+
async def generate(query: Query):
|
| 22 |
+
# Formats the prompt exactly like your training data
|
| 23 |
+
fmt_prompt = f"### Instruction:\n{query.prompt}\n\n### Response:\n"
|
| 24 |
+
output = llm(fmt_prompt, max_tokens=512, stop=["###"])
|
| 25 |
+
return {"response": output["choices"][0]["text"]}
|
| 26 |
+
|
| 27 |
+
@app.get("/")
|
| 28 |
+
def health():
|
| 29 |
+
return {"status": "Aevis API is Online"}
|