Spaces:
Runtime error
Runtime error
alvinfadli
commited on
Upload 2 files
Browse files- main.py +25 -0
- requirements.txt +6 -0
main.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ctransformers import AutoModelForCausalLM
|
2 |
+
from fastapi import FastAPI
|
3 |
+
from pydantic import BaseModel
|
4 |
+
|
5 |
+
|
6 |
+
llm = AutoModelForCausalLM.from_pretrained("llama2-tuned.gguf",
|
7 |
+
model_type='llama-2',
|
8 |
+
max_new_tokens = 1096,
|
9 |
+
threads = 3,
|
10 |
+
)
|
11 |
+
|
12 |
+
#Pydantic object
|
13 |
+
class validation(BaseModel):
|
14 |
+
prompt: str
|
15 |
+
#Fast API
|
16 |
+
app = FastAPI()
|
17 |
+
|
18 |
+
@app.post("/llm_on_cpu")
|
19 |
+
async def stream(item: validation):
|
20 |
+
system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.'
|
21 |
+
prompt = f"""<s>[INST] <<SYS>>
|
22 |
+
{system_prompt}
|
23 |
+
<</SYS>>
|
24 |
+
{item.prompt} [/INST]"""
|
25 |
+
return llm(prompt)
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
python-multipart
|
2 |
+
fastapi
|
3 |
+
pydantic
|
4 |
+
uvicorn
|
5 |
+
requests
|
6 |
+
ctransformers
|