MariamHussam commited on
Commit
18c1150
1 Parent(s): 14e29c5

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +19 -0
  2. app.py +30 -0
  3. requirements.txt +7 -0
Dockerfile ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+
12
+ COPY --chown=user ./requirements.txt requirements.txt
13
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
+
15
+
16
+ COPY --chown=user ./TowerInstruct-7B-v0.2.Q8_0.gguf TowerInstruct-7B-v0.2.Q8_0.gguf
17
+ COPY --chown=user ./app.py app.py
18
+
19
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ctransformers import AutoModelForCausalLM
2
+ from fastapi import FastAPI
3
+ from pydantic import BaseModel
4
+
5
+
6
+ llm = AutoModelForCausalLM.from_pretrained("TowerInstruct-7B-v0.2.Q8_0.gguf",
7
+ max_new_tokens = 2084,
8
+ threads = 3,
9
+ )
10
+
11
+ #Pydantic object
12
+ class validation(BaseModel):
13
+ prompt: str
14
+ #Fast API
15
+ app = FastAPI()
16
+
17
+ # <|im_start|>user
18
+ # Translate the following text from Portuguese into English.
19
+ # Portuguese: Um grupo de investigadores lançou um novo modelo para tarefas relacionadas com tradução.
20
+ # English:<|im_end|>
21
+ # <|im_start|>assistant
22
+
23
+ @app.post("/translate")
24
+ async def stream(item: validation):
25
+ translation_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.'
26
+ S_INST = "<|im_start|>"
27
+ E_INST = "<|im_end|>"
28
+ user, assistant = "user", "assistant"
29
+ prompt = f"{S_INST}{user}\n{translation_prompt}\nChinese:{item.prompt}\nEnglish:{E_INST}\n{S_INST}{assistant}\n"
30
+ return llm(prompt)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ python-multipart
2
+ fastapi
3
+ pydantic
4
+ uvicorn
5
+ requests
6
+ python-dotenv
7
+ ctransformers