MariamHussam commited on
Commit
aa72bf4
1 Parent(s): b855f71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -30
app.py CHANGED
@@ -1,30 +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)
 
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 = 'Translate the following text from Chinese into English.'
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)