GGUF
abhidgp1978 commited on
Commit
2bb5217
·
verified ·
1 Parent(s): 322c9fd

Update summary_api.py

Browse files
Files changed (1) hide show
  1. summary_api.py +23 -12
summary_api.py CHANGED
@@ -1,19 +1,30 @@
1
- # summary_api.py
2
  from fastapi import FastAPI, Request
3
  from pydantic import BaseModel
4
- from typing import List
5
- import subprocess
6
 
7
  app = FastAPI()
8
 
9
- class InputData(BaseModel):
10
- data: List[str]
 
 
 
 
 
 
 
 
 
 
11
 
12
- @app.post("/generate_summary")
13
- async def generate_summary(request: InputData):
14
- query = request.data[0]
15
-
16
- # Dummy logic – replace with actual inference using Gemma
17
- summary = f"📝 Summary: This is a placeholder summary for: {query}"
18
 
19
- return [summary]
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI, Request
2
  from pydantic import BaseModel
3
+ from llama_cpp import Llama
4
+ import uvicorn
5
 
6
  app = FastAPI()
7
 
8
+ # ✅ Load model from mistral-local repo directly
9
+ llm = Llama.from_pretrained(
10
+ repo_id="abhidgp1978/mistral-local",
11
+ filename="gemma-2b-it.gguf",
12
+ local_dir=".", # Root directory
13
+ n_ctx=2048,
14
+ n_threads=4,
15
+ n_gpu_layers=0,
16
+ f16_kv=True,
17
+ use_mlock=False,
18
+ verbose=False
19
+ )
20
 
21
+ class SummaryRequest(BaseModel):
22
+ data: list[str]
 
 
 
 
23
 
24
+ @app.post("/generate_summary")
25
+ async def generate_summary(req: SummaryRequest):
26
+ prompt = req.data[0]
27
+ full_prompt = f"Write a concise 100-word medical summary:\n\n{prompt.strip()}"
28
+ response = llm(full_prompt, max_tokens=256, stop=["User:", "Assistant:"], echo=False)
29
+ output = response["choices"][0]["text"].strip()
30
+ return {"summary": output}