Spaces:
Sleeping
Sleeping
File size: 515 Bytes
a95c82c 8b56784 a95c82c 8b56784 a95c82c 8b56784 a95c82c 8b56784 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import transformers
import torch
from fastapi import FastAPI
from pydantic import BaseModel
import uvicorn
app = FastAPI()
model_id = "meta-llama/Meta-Llama-3-8B"
pipeline = transformers.pipeline(
"text-generation", model=model_id, model_kwargs={"torch_dtype": torch.bfloat16}, device_map="auto"
)
class Item(BaseModel):
prompt: str
def generate(item: Item):
pipeline(item.prompt)
@app.post("/generate/")
async def generate_text(item: Item):
return {"response": generate(item)} |