Spaces:
Runtime error
Runtime error
Neupane9Sujal
commited on
Commit
•
891be39
1
Parent(s):
61ff518
Upload 3 files
Browse files- Dockerfile +25 -0
- app.py +17 -0
- requirements.txt +6 -0
Dockerfile
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
##set the work directory
|
4 |
+
WORKDIR /code
|
5 |
+
|
6 |
+
## copy the current directory contents into the container
|
7 |
+
COPY ./requirements.txt /code/requirements.txt
|
8 |
+
|
9 |
+
## install the required packages
|
10 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
11 |
+
|
12 |
+
##Setup a new user named named "user"
|
13 |
+
RUN useradd user
|
14 |
+
|
15 |
+
##Add the user to the container
|
16 |
+
USER user
|
17 |
+
|
18 |
+
ENV HOME=/home/user \
|
19 |
+
PATH = /home/user/.local/bin:$PATH
|
20 |
+
|
21 |
+
WORKDIR $HOME/app
|
22 |
+
|
23 |
+
COPY --chown . $HOME/app
|
24 |
+
|
25 |
+
CMD["uvicorn","app:app","--host","0.0.0.0", "--port", "8000"]
|
app.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from fastapi import FastAPI
|
3 |
+
from ctransformers import AutoModelForCausalLM
|
4 |
+
|
5 |
+
##create a new FastAPI app instance
|
6 |
+
app = FastAPI()
|
7 |
+
|
8 |
+
def get_llm():
|
9 |
+
model_path = "TheBloke/CodeLlama-7B-GGUF"
|
10 |
+
llm = AutoModelForCausalLM.from_pretrained("TheBloke/CodeLlama-7B-GGUF", model_type="llama")
|
11 |
+
return llm
|
12 |
+
|
13 |
+
@app.get("/generate")
|
14 |
+
def generate(text:str) ->dict:
|
15 |
+
llm = get_llm()
|
16 |
+
res = llm(text)
|
17 |
+
return {"text":res}
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn[standard]
|
3 |
+
ctransformers
|
4 |
+
transformers
|
5 |
+
torch
|
6 |
+
sentencepiece
|