Spaces:
No application file
No application file
Download app.py from sucheendra93/custom-model: direct link, hf CLI and curl.
- Browser
- Download file 547 Bytes
-
https://huggingface.co/spaces/sucheendra93/custom-model/resolve/main/app.py
- Command line
-
hf download hf://spaces/sucheendra93/custom-model/app.py
-
curl -L -o app.py https://huggingface.co/spaces/sucheendra93/custom-model/resolve/main/app.py
547 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from transformers import pipeline | |
| app = FastAPI() | |
| generator = pipeline( | |
| "text-generation", | |
| model="meta-llama/Llama-3.1-8B-Instruct", # or your HF model | |
| device=0 # remove if CPU | |
| ) | |
| class Request(BaseModel): | |
| prompt: str | |
| max_new_tokens: int = 150 | |
| def generate(req: Request): | |
| output = generator( | |
| req.prompt, | |
| max_new_tokens=req.max_new_tokens, | |
| do_sample=True, | |
| ) | |
| return {"result": output[0]["generated_text"]} | |