Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,18 @@
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-llm-7b-base")
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
"deepseek-ai/deepseek-llm-7b-base",
|
| 10 |
+
torch_dtype=torch.float16,
|
| 11 |
+
device_map="auto"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
@app.get("/ask")
|
| 15 |
+
def ask(prompt: str):
|
| 16 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 17 |
+
outputs = model.generate(**inputs, max_new_tokens=100)
|
| 18 |
+
return {"response": tokenizer.decode(outputs[0], skip_special_tokens=True)}
|