Mikecode123 commited on
Commit
3150e9f
ยท
verified ยท
1 Parent(s): 9a6ec51

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. main.py +40 -0
  3. qwen2-1_5b-instruct-q4_0.gguf +3 -0
  4. requirement.txt +5 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ qwen2-1_5b-instruct-q4_0.gguf filter=lfs diff=lfs merge=lfs -text
main.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # ๐Ÿ‘‡ Request body structure
9
+ class PromptRequest(BaseModel):
10
+ prompt: str
11
+ max_tokens: int = 200
12
+
13
+ # ๐Ÿ‘‡ Download model from your HF repo
14
+ MODEL_PATH = hf_hub_download(
15
+ repo_id="your-username/qwen-gguf", # CHANGE THIS
16
+ filename="qwen2-1_5b-instruct-q4_0.gguf"
17
+ )
18
+
19
+ # ๐Ÿ‘‡ Load model once (very important)
20
+ llm = Llama(
21
+ model_path=MODEL_PATH,
22
+ n_ctx=1024, # keep low for HF free tier
23
+ n_threads=2 # reduce CPU usage
24
+ )
25
+
26
+ @app.get("/")
27
+ def home():
28
+ return {"status": "AI is running"}
29
+
30
+ @app.post("/chat")
31
+ def chat(req: PromptRequest):
32
+ output = llm(
33
+ req.prompt,
34
+ max_tokens=req.max_tokens,
35
+ stop=["</s>"]
36
+ )
37
+
38
+ return {
39
+ "response": output["choices"][0]["text"]
40
+ }
qwen2-1_5b-instruct-q4_0.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:106c176ae807b164f16e2898e8f0267062e3c93c3c18c8267cf9e4ee90766beb
3
+ size 937532800
requirement.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ llama-cpp-python
4
+ huggingface_hub
5
+ pydantic