VietCat commited on
Commit
43cc2bd
·
1 Parent(s): b987767

init project

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. .gitignore +2 -0
  3. Dockerfile +16 -0
  4. app.py +21 -0
  5. requirements.txt +3 -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
+ *.gguf filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # files
2
+ *.DS_Store
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ # Đặt biến môi trường cho cache (sử dụng HF_HOME thay vì TRANSFORMERS_CACHE)
4
+ ENV HF_HOME=/tmp/.cache
5
+
6
+ WORKDIR /app
7
+
8
+ COPY requirements.txt .
9
+ RUN pip install --no-cache-dir -r requirements.txt
10
+
11
+ COPY . .
12
+
13
+ # Expose port mặc định HFS (7860)
14
+ EXPOSE 7860
15
+
16
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from pydantic import BaseModel
3
+ from llama_cpp import Llama
4
+
5
+ app = FastAPI()
6
+
7
+ # Load the model
8
+ llm = Llama(
9
+ model_path="models/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf",
10
+ n_ctx=1024,
11
+ n_threads=2 # <= phù hợp HFS Free Tier
12
+ )
13
+
14
+ class PromptRequest(BaseModel):
15
+ prompt: str
16
+
17
+ @app.post("/generate")
18
+ async def generate_text(request: PromptRequest):
19
+ prompt = request.prompt
20
+ output = llm(prompt)
21
+ return {"response": output["choices"][0]["text"]}
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ llama-cpp-python==0.2.24