Spaces:
Runtime error
Runtime error
kaanyarali1
commited on
Commit
·
37527e9
1
Parent(s):
73141d0
llm try
Browse files
app.py
CHANGED
@@ -1,10 +1,26 @@
|
|
1 |
from fastapi import FastAPI
|
|
|
|
|
2 |
|
3 |
# Create an instance of the FastAPI class
|
4 |
app = FastAPI()
|
5 |
|
6 |
# Define a route for the root endpoint
|
7 |
-
@app.get("/")
|
8 |
async def read_root():
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
|
|
1 |
from fastapi import FastAPI
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
|
5 |
# Create an instance of the FastAPI class
|
6 |
app = FastAPI()
|
7 |
|
8 |
# Define a route for the root endpoint
|
9 |
+
@app.get("/llm")
|
10 |
async def read_root():
|
11 |
+
device = "cpu"
|
12 |
+
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
|
14 |
+
text = """<s>[INST] What is your favourite condiment? [/INST]
|
15 |
+
"""
|
16 |
+
encodeds = tokenizer(text, return_tensors="pt", add_special_tokens=False)
|
17 |
+
model_inputs = encodeds.to(device)
|
18 |
+
model.to(device)
|
19 |
+
generated_ids = model.generate(**model_inputs, max_new_tokens=1000, do_sample=True)
|
20 |
+
decoded = tokenizer.batch_decode(generated_ids)
|
21 |
+
print(decoded[0])
|
22 |
+
return {"message": decoded[0]}
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
|