Rixf123 commited on
Commit
fcd39e1
·
verified ·
1 Parent(s): b999012

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from huggingface_hub import hf_hub_download
4
+ from llama_cpp import Llama
5
+
6
+ app = FastAPI()
7
+
8
+ # Download model (replace filename with the exact GGUF file)
9
+ model_path = hf_hub_download(
10
+ repo_id="mradermacher/Mythos-nano-i1-GGUF",
11
+ filename="Mythos-nano-i1.Q4_K_M.gguf"
12
+ )
13
+
14
+ llm = Llama(
15
+ model_path=model_path,
16
+ n_ctx=2048
17
+ )
18
+
19
+ class Request(BaseModel):
20
+ prompt: str
21
+ max_tokens: int = 256
22
+
23
+ @app.post("/generate")
24
+ async def generate(req: Request):
25
+ output = llm(
26
+ req.prompt,
27
+ max_tokens=req.max_tokens
28
+ )
29
+
30
+ return {
31
+ "response": output["choices"][0]["text"]
32
+ }