Spaces:
Runtime error
Runtime error
Download main.py from Akbartus/FastAPIExample: direct link, hf CLI and curl.
- Browser
- Download file 515 Bytes
-
https://huggingface.co/spaces/Akbartus/FastAPIExample/resolve/a95c82cc2eb807d99ed1872eb1b843a2b8bbcaa9/main.py
- Command line
-
hf download hf://spaces/Akbartus/FastAPIExample@a95c82cc2eb807d99ed1872eb1b843a2b8bbcaa9/main.py
-
curl -L -o main.py https://huggingface.co/spaces/Akbartus/FastAPIExample/resolve/a95c82cc2eb807d99ed1872eb1b843a2b8bbcaa9/main.py
515 Bytes
| 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) | |
| async def generate_text(item: Item): | |
| return {"response": generate(item)} |